package com.smedi.ismedi.progress.core.port.adapter.persistence.repository.impl;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.ObjectUtils;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.github.xiaoymin.knife4j.core.util.CollectionUtils;
import com.smedi.ismedi.authority.starter.util.AuthorityUtil;
import com.smedi.ismedi.constructionproject.api.dto.response.ProjectBasicResponse;
import com.smedi.ismedi.constructionproject.api.dto.response.resp.ProjectResp;
import com.smedi.ismedi.progress.api.dto.response.*;
import com.smedi.ismedi.progress.core.application.command.*;
import com.smedi.ismedi.progress.core.application.service.ProgressReportApplicationService;
import com.smedi.ismedi.progress.core.domain.aggregatemodel.*;
import com.smedi.ismedi.progress.core.domain.dto.FileQuery;
import com.smedi.ismedi.progress.core.domain.dto.PersonQuery;
import com.smedi.ismedi.progress.core.domain.dto.ProjectQuery;
import com.smedi.ismedi.progress.core.domain.repository.*;
import com.smedi.ismedi.progress.core.port.adapter.convert.AdapterConverter;
import com.smedi.ismedi.progress.core.port.adapter.persistence.model.*;
import com.smedi.ismedi.progress.core.port.adapter.persistence.mybatis.mapper.*;
import com.smedi.ismedi.progress.core.port.adapter.service.ProcessRemoteService;
import com.smedi.ismedi.progress.core.port.adapter.service.ProjectRemoteService;
import com.smedi.ismedi.web.starter.common.ResponseData;
import com.smedi.ismedi.web.starter.exception.ErrorItem;
import com.smedi.ismedi.web.starter.exception.LogicException;
import lombok.AllArgsConstructor;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.math.BigDecimal;
import java.text.DecimalFormat;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.format.DateTimeFormatter;
import java.time.temporal.ChronoUnit;
import java.time.temporal.TemporalAdjusters;
import java.time.temporal.WeekFields;
import java.util.*;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import static com.smedi.ismedi.progress.core.infrastructure.constant.ConstantField.*;
import static java.time.format.DateTimeFormatter.ISO_DATE;

/**
 * 进度计划仓库实现类
 *
 * @author liaojiajie
 * @date 2022/9/21
 */
@Repository
@RequiredArgsConstructor
@Slf4j
public class ProgressReportRepositoryImpl implements ProgressReportRepository {

    private final ProgressReportMapper progressReportMapper;
    private final AdapterConverter adapterConverter;
    private final ProgressMapper progressMapper;
    private final AuthorityUtil authorityUtil;
    private final ProjectScheduleDetaillMapper projectScheduleDetaillMapper;
    private final ProgressReportDetailMapper progressReportDetailMapper;
    private final ProgressProjectRepository progressProjectRepository;
    private final ProcessRemoteService processRemoteService;
    private final ProgressAttachmentImageMapper progressAttachmentImageMapper;
    private final FileRepository fileRepository;
    private final ProjectAttachmentImageMapper projectAttachmentImageMapper;
    private final ProjectRemoteService projectRemoteService;

    private final VersionDetailMapper versionDetailMapper;
    private final PersonRepository personRepository;
    private final ProjectRepository projectRepository;

    @Value("${message-notify.project-manager.role}")
    private String messageNotifyProjectManagerRole;// 施工项目经理

    @Override
    public ProgressReport getProgressWeekReportOne(ProgressReportOneQuery progressReportQuery) {
        LambdaQueryWrapper<ProgressReportEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportQuery.getId()), ProgressReportEntity::getId, progressReportQuery.getId());
        ProgressReportEntity progressReportEntity = progressReportMapper.selectOne(lambdaQueryWrapper);
//        ProgressReport progressReport = adapterConverter.prpgressReportEntityToProgressReport(progressReportEntity);
        return this.extend(progressReportEntity);
    }

    private ProgressReport extend(ProgressReportEntity progressReportEntity) {
        if (progressReportEntity == null) {
            return null;
        }

        List<ProgressReportEntity> progressReportEntites = new ArrayList<>();
        progressReportEntites.add(progressReportEntity);
        List<ProgressReport> progressReportList = this.extend(progressReportEntites);

        return progressReportList.get(0);
    }

    private List<ProgressReport> extend(List<ProgressReportEntity> progressReportEntites) {
        if (progressReportEntites.isEmpty()) {
            return new ArrayList<>();
        }
        Set<Long> projectIds = new HashSet<>();
        Set<Long> personIds = new HashSet<>();
        List<ProgressReport> rogressReportList = new ArrayList<>();
        for (ProgressReportEntity progressReportEntity : progressReportEntites) {
            Long projectId = progressReportEntity.getProjectId();
            if (projectId != null) {
                projectIds.add(projectId);
            }
            personIds.add(progressReportEntity.getCreatedUserId());
        }

        List<Project> projects = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(projectIds)) {
            projects = projectRepository.getProjectList(ProjectQuery.builder().ids(new ArrayList<>(projectIds)).build());
        }
        Map<Long, Project> idProjectMap = new HashMap<>();
        for (Project project : projects) {
            idProjectMap.put(project.getId(), project);
        }
        List<Person> people = new ArrayList<>();
        if (CollectionUtils.isNotEmpty(personIds)) {
            people = personRepository.getPersonList(PersonQuery.builder().ids(new ArrayList<>(personIds)).build());
        }
        Map<Long, Person> idPeopleMap = new HashMap<>();
        for (Person application : people) {
            idPeopleMap.put(application.getId(), application);
        }

        for (ProgressReportEntity progressReportEntity : progressReportEntites) {
            ProgressReport progressReport = adapterConverter.progressReportEntityToProgressReport(progressReportEntity);
            progressReport.setProject(idProjectMap.getOrDefault(progressReportEntity.getProjectId(), new Project(progressReportEntity.getProjectId())));
            progressReport.setPerson(idPeopleMap.getOrDefault(progressReportEntity.getCreatedUserId(), new Person(progressReportEntity.getCreatedUserId())));
            rogressReportList.add(progressReport);
        }

        return rogressReportList;
    }

    @Override
    @Transactional
    public void updateProgressReportData(Progress versionManage) {
        // 更新对应的草稿周月报数据
        // 查询 周报月报草稿信息 更新 计划开始时间，计划完成时间，任务名称 （里程碑、关键线路、一级任务）
        // 查询 周月报主表 草稿信息的主表id
        LambdaQueryWrapper<ProgressReportEntity> prpgressReport = new LambdaQueryWrapper<>();
        prpgressReport.eq(ObjectUtils.isNotNull(versionManage.getProjectId()), ProgressReportEntity::getProjectId, versionManage.getProjectId());
        prpgressReport.in(ProgressReportEntity::getStatus, new ArrayList<>(Arrays.asList(0l, 2l)));
//        prpgressReport.isNull(ProgressReportEntity::getConstructionManagerApproval);
        List<ProgressReportEntity> ProgressReports = progressReportMapper.selectList(prpgressReport);
        List<Long> ids = ProgressReports.stream().distinct().map(ProgressReportEntity -> ProgressReportEntity.getId()).collect(Collectors.toList());
        // 根据周月报主表数据查询 详情信息
//        ProgressReports.forEach(b -> {
//            ids.add(b.getId());
//        });
        LambdaQueryWrapper<ProgressReportDetailEntity> progressReportDatail = new LambdaQueryWrapper<>();
        progressReportDatail.in(CollectionUtils.isNotEmpty(ids), ProgressReportDetailEntity::getProgressWeekMonthReportId, ids);
        progressReportDatail.eq(ObjectUtils.isNotNull(versionManage.getProjectId()), ProgressReportDetailEntity::getProjectId, versionManage.getProjectId());
        Integer progressReportDetailCount = progressReportDetailMapper.selectCount(progressReportDatail);
        if (progressReportDetailCount > 0 && ProgressReports.size() > 0) {
            // 根据周月报主表id 、项目id、查找对应的详情表的任务数据进行更新
            LambdaQueryWrapper<VersionDetailEntity> verseionDetail = new LambdaQueryWrapper<>();
            verseionDetail.eq(ObjectUtils.isNotNull(versionManage.getId()), VersionDetailEntity::getVersionManageId, versionManage.getId());
            verseionDetail.eq(ObjectUtils.isNotNull(versionManage.getProjectId()), VersionDetailEntity::getProjectId, versionManage.getProjectId());
//            verseionDetail.in(VersionDetailEntity::getType, new ArrayList<Long>(Arrays.asList(0l, 1l, 4l)));
            List<VersionDetailEntity> versionDetailLists = versionDetailMapper.selectList(verseionDetail);

            // 查询报表中 所有的任务
            if (!ids.isEmpty()) {
                for (int i = 0; i < ids.size(); i++) {
                    LambdaQueryWrapper<ProgressReportDetailEntity> reportDatail = new LambdaQueryWrapper<>();
                    reportDatail.eq(ObjectUtils.isNotNull(ids.get(i)), ProgressReportDetailEntity::getProgressWeekMonthReportId, ids.get(i));
                    List<ProgressReportDetailEntity> progressReportDetails = progressReportDetailMapper.selectList(reportDatail);
                    List<ProgressReportDetailEntity> newProgressReportDetailEntity = new ArrayList<>();
                    // 不存在插入
                    List<VersionDetailEntity> versiondetailList = versionDetailLists.stream().filter(versionDetailList -> !progressReportDetails.stream().anyMatch(proDetail -> (versionDetailList.getName().equals(proDetail.getName()) && versionDetailList.getParentName().equals(proDetail.getParentName())))).collect(Collectors.toList());
                    if (!versiondetailList.isEmpty()) {
                        int finalI = i;
                        //更新项目详情表中  (任务/里程碑)名称、类型(0、里程碑 1、关键任务  3、其他)、计划开始时间、计划完成时间、计划工期、负责人、版本号
                        versiondetailList.forEach(version -> {
                            ProgressReportDetailEntity progressReportDetailEntityNew = adapterConverter.versionToProgressReportDetailEntity(version);
                            progressReportDetailEntityNew.setProgressWeekMonthReportId(ids.get(finalI));
                            progressReportDetailEntityNew.setCreatedUserId(authorityUtil.getPersonId());
                            progressReportDetailEntityNew.setCreatedDate(LocalDateTime.now());
                            progressReportDetailEntityNew.setCompletion(0l);
                            progressReportDetailEntityNew.setLagTime(0l);
                            progressReportDetailEntityNew.setStatus(1l);
                            newProgressReportDetailEntity.add(progressReportDetailEntityNew);
//                            progressReportDetailMapper.insert(progressReportDetailEntityNew);
                        });
                    }
                    if (!newProgressReportDetailEntity.isEmpty()){
                        progressReportDetailMapper.insertBatch(newProgressReportDetailEntity);
                    }
                    // 多余删除
                    // 处理对应图片信息
                    List<ProgressAttachmentImageEntity> progressAttachmentImageList = new ArrayList<>();
                    List<ProgressReportDetailEntity> progressReportDetailList = progressReportDetails.stream().filter(versionDetailList -> !versionDetailLists.stream().anyMatch(proDetail -> (versionDetailList.getName().equals(proDetail.getName()) && versionDetailList.getParentName().equals(proDetail.getParentName())))).collect(Collectors.toList());
                    if (!progressReportDetailList.isEmpty()) {
                        // 处理对应的图片数据
                        progressReportDetailList.forEach(image -> {
                            // 查询对应的图片信息
                            LambdaQueryWrapper<ProgressAttachmentImageEntity> projectAttachmentImageEntity = new LambdaQueryWrapper<>();
                            projectAttachmentImageEntity.eq(ObjectUtils.isNotNull(image.getId()), ProgressAttachmentImageEntity::getProgressWeekMonthDetailId, image.getId().toString() + image.getProgressWeekMonthReportId().toString());
                            List<ProgressAttachmentImageEntity> projectAttachmentImages = progressAttachmentImageMapper.selectList(projectAttachmentImageEntity);
                            progressAttachmentImageList.addAll(projectAttachmentImages);
                        });
                        progressReportDetailMapper.deleteOther(progressReportDetailList);
                    }
                    if (!progressAttachmentImageList.isEmpty()) {
                        progressAttachmentImageMapper.deleteBatch(progressAttachmentImageList);
                    }
                    // 存在更新
                    List<ProgressReportDetailEntity> updateProgressReportDetailEntity = new ArrayList<>();
                    List<VersionDetailEntity> versiondetailLists = versionDetailLists.stream().filter(versionDetailList -> progressReportDetails.stream().anyMatch(proDetail -> (versionDetailList.getName().equals(proDetail.getName()) && versionDetailList.getParentName().equals(proDetail.getParentName())))).collect(Collectors.toList());
//                    List<ProgressReportDetailEntity> progressReportDetailLists = progressReportDetails.stream().filter(progressReportDetailList1 -> versionDetailLists.stream().anyMatch(proDetail -> (progressReportDetailList1.getName().equals(proDetail.getName()) && progressReportDetailList1.getParentName().equals(proDetail.getParentName())))).collect(Collectors.toList());
                    if (!versiondetailLists.isEmpty()) {
                        int finalI1 = i;
                        versiondetailLists.forEach(updateVersion -> {
                            ProgressReportDetailEntity progressReportDetailEntityNew = adapterConverter.versionToProgressReportDetailEntity(updateVersion);
                            progressReportDetailEntityNew.setLatestUpdatedDate(LocalDateTime.now());
                            progressReportDetailEntityNew.setLatestUpdatedUserId(authorityUtil.getPersonId());
                            progressReportDetailEntityNew.setParentName(updateVersion.getParentName());
                            progressReportDetailEntityNew.setId(updateVersion.getId());
                            progressReportDetailEntityNew.setSortIndex(updateVersion.getSortIndex());
                            progressReportDetailEntityNew.setParentId(updateVersion.getParentId());
                            progressReportDetailEntityNew.setNamePrefix(updateVersion.getNamePrefix());
                            progressReportDetailEntityNew.setType(updateVersion.getType());
                            progressReportDetailEntityNew.setProgressWeekMonthReportId(ids.get(finalI1));
                            // 查询对应的图片信息
                            LambdaQueryWrapper<ProgressReportDetailEntity> progressReportDetailEntity = new LambdaQueryWrapper<>();
                            progressReportDetailEntity.eq(ObjectUtils.isNotNull(updateVersion.getName()), ProgressReportDetailEntity::getName, updateVersion.getName());
                            progressReportDetailEntity.eq(ObjectUtils.isNotNull(updateVersion.getParentName()), ProgressReportDetailEntity::getParentName, updateVersion.getParentName());
                            progressReportDetailEntity.eq(ObjectUtils.isNotNull(updateVersion.getProjectId()), ProgressReportDetailEntity::getProjectId, updateVersion.getProjectId());
                            progressReportDetailEntity.eq(ObjectUtils.isNotNull(ids.get(finalI1)), ProgressReportDetailEntity::getProgressWeekMonthReportId, ids.get(finalI1));
                            List<ProgressReportDetailEntity> progressReportDetailss = progressReportDetailMapper.selectList(progressReportDetailEntity);
                            List<String> idss = progressReportDetailss.stream().distinct().map(x -> (x.getId().toString() + x.getProgressWeekMonthReportId().toString())).collect(Collectors.toList());
                            // 查询图片信息
                            LambdaQueryWrapper<ProgressAttachmentImageEntity> progressAttachmentImageEntity = new LambdaQueryWrapper<>();
                            progressAttachmentImageEntity.in(ObjectUtils.isNotNull(idss), ProgressAttachmentImageEntity::getProgressWeekMonthDetailId, idss);
                            List<ProgressAttachmentImageEntity> projectAttachmentImages = progressAttachmentImageMapper.selectList(progressAttachmentImageEntity);
                            projectAttachmentImages.forEach(m -> {
                                ProgressAttachmentImageEntity progressImage = adapterConverter.mwToProgressAttachmentImageEntity(m);
                                progressImage.setProgressWeekMonthDetailId(updateVersion.getId().toString() + ids.get(finalI1).toString());
                                QueryWrapper<ProgressAttachmentImageEntity> queryWrapper = new QueryWrapper<>();
                                queryWrapper.eq("id", m.getId());
                                queryWrapper.eq("progress_week_month_detail_id", m.getProgressWeekMonthDetailId());
                                progressAttachmentImageMapper.update(progressImage, queryWrapper);
                            });
                            updateProgressReportDetailEntity.add(progressReportDetailEntityNew);
//                            progressReportDetailMapper.updateDetail(progressReportDetailEntityNew);
                        });
                        if (!updateProgressReportDetailEntity.isEmpty()){
                            progressReportDetailMapper.updateDetail(updateProgressReportDetailEntity);
                        }
                    }
                }
            }
        }
    }

    @Override
    public ProgressReport updateProgressReport(ProgressReport weekReport) {
        ProgressReportEntity progressReportEntity = adapterConverter.weekReportToProgressReportEntity(weekReport);
        if (ObjectUtils.isNull(progressReportEntity.getId())) {
            progressReportMapper.insert(progressReportEntity);
        }
        if (ObjectUtils.isNotNull(progressReportEntity.getId())) {
//            progressReportMapper.updateDate(progressReportEntity);
            progressReportMapper.updateById(progressReportEntity);
        }

        return adapterConverter.progressReportEntityToProgressReport(progressReportEntity);
    }

    @Override
    public ProjectBasicResponse getProject(Long projectId) {
        return progressProjectRepository.getProject(projectId);
    }

    @Override
    public void updateReportDetailToProject(ProgressReport weekReport) {
        log.info("开始更新进度周、月报，此次更新的类型为（1，周报，2，月报）："+weekReport.getType());
        // 判断周报统计时段结束时间是否大于主表中需要更新的时间段（月报是判断是否存在大于当月时间） 大于更新，则不更新，并把主表中的时间更新为周报统计结束时间段，如是月报则更新为月报的月底时间。
        String updateDate = "";
        if (weekReport.getType() == MONTH_TYPE) { // 月报
            // 根据统计时段判断主表值
            LocalDateTime lastDay = weekReport.getStatisticalEndTime().with(TemporalAdjusters.lastDayOfMonth());
            updateDate = DateUtil.format(lastDay, "yyyy-MM-dd");
        } else if (weekReport.getType() == WEEK_TYPE) { // 周报
            updateDate = DateUtil.format(weekReport.getStatisticalEndTime(), "yyyy-MM-dd");
        }
        // 查询 根据项目id
        LambdaQueryWrapper<ProgressEntity> projectEntity = new LambdaQueryWrapper<>();
        projectEntity.eq(ObjectUtils.isNotNull(weekReport.getProjectId()), ProgressEntity::getProjectId, weekReport.getProjectId());
        projectEntity.gt(ObjectUtils.isNotNull(updateDate), ProgressEntity::getUpdateDate, updateDate);
        ProgressEntity progressProjectEntity = progressMapper.selectOne(projectEntity);
        log.info("查询项目，参数，projectId:"+weekReport.getProjectId()+"，updateDate："+updateDate);
        if (progressProjectEntity == null) {
            log.info("查询项目为空，开始更新数据");
            Integer maxLagTime = 0;
            log.info("查询项目为空，开始更新数据");
            // 根据周月报表id获取周月报详情数据
            LambdaQueryWrapper<ProgressReportDetailEntity> progressReportDatail = new LambdaQueryWrapper<>();
            progressReportDatail.eq(ObjectUtils.isNotNull(weekReport.getProjectId()), ProgressReportDetailEntity::getProjectId, weekReport.getProjectId());
            progressReportDatail.eq(ObjectUtils.isNotNull(weekReport.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, weekReport.getId());
            List<ProgressReportDetailEntity> progressReportDatailList = progressReportDetailMapper.selectList(progressReportDatail);
            List<ProgressDetailEntity> progressDetailList =  new ArrayList<>();
            List<ProjectAttachmentImageEntity> projectAttachmentImageList =  new ArrayList<>();
            for(ProgressReportDetailEntity v : progressReportDatailList){
                // 根据项目id 任务名称 更新对应的数据
                LambdaQueryWrapper<ProgressDetailEntity> progressDetail = new LambdaQueryWrapper<>();
                progressDetail.eq(ObjectUtils.isNotNull(v.getProjectId()), ProgressDetailEntity::getProjectId, v.getProjectId());
                progressDetail.eq(ObjectUtils.isNotNull(v.getName()), ProgressDetailEntity::getName, v.getName());
                progressDetail.eq(ObjectUtils.isNotNull(v.getParentName()), ProgressDetailEntity::getParentName, v.getParentName());
                ProgressDetailEntity progressDetailEntity = projectScheduleDetaillMapper.selectOne(progressDetail);
                if (progressDetailEntity != null) {
                    // 更新项目详情表
                    /**
                     * 详情表：实际开始时间、实际完成时间、完成情况(0、未完成  1、完成)、进度状态(0、滞后  1、正常)、滞后时长、照片url、完成百分比
                     * 主表：实际开始时间、实际完成时间、进度状态(0、滞后  1、正常)、、照片url、完成百分比、里程碑进度状态(0、滞后  1、正常)、关键任务进度状态(0、滞后  1、正常)、累积产值
                     */
                    if(v.getCompletion() != null){
                        if(v.getCompletion().intValue() == 0 || Integer.parseInt(v.getPercentage()) < 100){
                            if(v.getLagTime().intValue() > maxLagTime){
                                maxLagTime = v.getLagTime().intValue();
                            }
                        }
                    }else{
                        if(Integer.parseInt(v.getPercentage()) < 100){
                            if(v.getLagTime().intValue() > maxLagTime){
                                maxLagTime = v.getLagTime().intValue();
                            }
                        }
                    }
                    progressDetailEntity.setRealStartTime(v.getRealStartTime());
                    progressDetailEntity.setRealEndTime(v.getRealEndTime());
                    progressDetailEntity.setCompletion(v.getCompletion()!=null ? v.getCompletion().intValue(): null);
                    progressDetailEntity.setStatus(v.getStatus().intValue());
                    progressDetailEntity.setLagTime(v.getLagTime().intValue());
                    progressDetailEntity.setLatestUpdatedDate(LocalDateTime.now());
                    progressDetailEntity.setLatestUpdatedUserId(authorityUtil.getPersonId());
//                progressDetailEntity.setPhotoUrl(v.getPhotoUrl());
                    // 更新图片信息 查询 附件表中
                    LambdaQueryWrapper<ProjectAttachmentImageEntity> projectAttachmentImageEntity = new LambdaQueryWrapper<>();
                    projectAttachmentImageEntity.eq(ObjectUtils.isNotNull(progressDetailEntity.getId()), ProjectAttachmentImageEntity::getProjectScheduleDetailId, progressDetailEntity.getId());
                    //  删除所有的图片
                    projectAttachmentImageMapper.delete(projectAttachmentImageEntity);
                    // 插入 最新的图片信息 查询 查询最新的图片
                    LambdaQueryWrapper<ProgressAttachmentImageEntity> progressAttachmentImageEntity = new LambdaQueryWrapper<>();
                    progressAttachmentImageEntity.eq(ObjectUtils.isNotNull(v.getId().toString() + v.getProgressWeekMonthReportId().toString()), ProgressAttachmentImageEntity::getProgressWeekMonthDetailId, v.getId().toString() + v.getProgressWeekMonthReportId().toString());
                    List<ProgressAttachmentImageEntity> progressAttachmentImages = progressAttachmentImageMapper.selectList(progressAttachmentImageEntity);
                    if(v.getCompletion() != null){
                        if (1 == v.getCompletion().intValue()) {
                            progressDetailEntity.setPercentage("100");
                        } else {
                            progressDetailEntity.setPercentage(v.getPercentage());
                        }
                    }
                    if ("100".equals(v.getPercentage()) && v.getPercentage() != null) {
                        progressDetailEntity.setEditFlag(0);
                    }
                    if(v.getCompletion() != null){
                        if (1 == v.getCompletion() && v.getCompletion() != null) {
                            progressDetailEntity.setEditFlag(0);
                        }
                    }

                    progressDetailList.add(progressDetailEntity);
//                    projectScheduleDetaillMapper.updateByIdNes(progressDetailEntity);
                    progressAttachmentImages.forEach(m -> {
                        ProjectAttachmentImageEntity projectAttachmentImage = adapterConverter.mToProjectAttachmentImageEntity(m);
                        projectAttachmentImage.setProjectScheduleDetailId(progressDetailEntity.getId());
                        projectAttachmentImageList.add(projectAttachmentImage);
//                        projectAttachmentImageMapper.insert(projectAttachmentImage);
                    });
                }
            }
            if (!progressDetailList.isEmpty()){
                projectScheduleDetaillMapper.updateByIdNes(progressDetailList);
            }
            if (!projectAttachmentImageList.isEmpty()){
                projectAttachmentImageMapper.insertBact(projectAttachmentImageList);
            }
            LambdaQueryWrapper<ProgressEntity> progressProject = new LambdaQueryWrapper<>();
            progressProject.eq(ObjectUtils.isNotNull(weekReport.getProjectId()), ProgressEntity::getProjectId, weekReport.getProjectId());
            ProgressEntity progressEntity = progressMapper.selectOne(progressProject);
            // 获取项目合同金额
            if (progressEntity != null) {
                // 查询项目详单表中最小实际时间，最大时间时间 ，进度状态情况（有一个是滞后就是滞后状态），滞后时长(更新最长的一条数据) 本项目的累积产值相加 月报  完成百分比（月报中累计上报产值/项目合同金额）  里程碑进度状态(0、滞后  1、正常)（有一个滞后就是滞后） 关键任务进度状态(0、滞后  1、正常)（有一个滞后就是滞后）
                // 查询项目详情表中最小实际时间，最大时间时间
                ProgressDetailEntity maxAndMinTime = projectScheduleDetaillMapper.findMaxAndMinTime(progressEntity);
                if(maxAndMinTime != null){
                    progressEntity.setRealStartTime(maxAndMinTime.getRealStartTime());
                    //进度计划中所有一级任务、关键任务、里程碑都完成时，实际完成时间中最晚的日期；当有一级任务关键任务里程碑任务未完成时，实际完工日期为空
                    LambdaQueryWrapper<ProgressDetailEntity> wrapper = new LambdaQueryWrapper<>();

                    wrapper.eq(ProgressDetailEntity::getProjectId, progressEntity.getProjectId());
                    wrapper.eq(ProgressDetailEntity::getProjectScheduleId, progressEntity.getId());
                    //数据库存储是用逗号分开的，不能直接用in,eq去查询：Type = 0,1,5
                    wrapper.and(wp -> {
                        wp.like(ProgressDetailEntity::getType, "0");
                        wp.or();
                        wp.like(ProgressDetailEntity::getType, "1");
                        wp.or();
                        wp.like(ProgressDetailEntity::getType, "4");
                    });
                    List<ProgressDetailEntity> list = projectScheduleDetaillMapper.selectList(wrapper);
                    //完成数
                    int completionNum = 0;
                    for (ProgressDetailEntity entity: list) {
                        if(entity.getCompletion() != null){
                            if (entity.getCompletion() == 1) {
                                completionNum++;
                            }
                        }

                    }
                    if (completionNum == list.size()) {
                        progressEntity.setRealEndTime(maxAndMinTime.getRealEndTime());
                    } else {
                        progressEntity.setRealEndTime(null);
                    }
                    // 查询 进度状态情况（有一个是滞后就是滞后状态）change 2023年6月5日17:53:11
                    // Integer countNum = projectScheduleDetaillMapper.findProgressStatus(progressEntity);
                    List<ProgressDetailStatus> progressDetailStatuses = projectScheduleDetaillMapper.selectStatus(progressEntity.getProjectId(), progressEntity.getId());
                    // 设置项目整体完成状态,详情见ProgressDetailStatus#isComplete
                    if (ProgressDetailStatus.isComplete(progressDetailStatuses)) {
                        progressEntity.setProgressStatus(1);
                    } else {
                        progressEntity.setProgressStatus(0);
                    }
                    if(maxLagTime == 0){
                        progressEntity.setProgressStatus(1);
                    }else{
                        progressEntity.setProgressStatus(0);
                    }
                    progressEntity.setLagTime(maxLagTime);
                    // 滞后时长(更新最长的一条数据)
                /*Integer lagTimeMax = projectScheduleDetaillMapper.findMaxLagTime(progressEntity);
                progressEntity.setLagTime(lagTimeMax);*/
                    // 查询 本项目的累积产值相加 月报
                    Integer accumulationOutputSum = 0;
                    if (weekReport.getType() == MONTH_TYPE) {
                        accumulationOutputSum = progressReportMapper.findPercentageNum(weekReport);
                        progressEntity.setAccumulationOutput(accumulationOutputSum + weekReport.getReportOutputValue().intValue());
                    }
                    // 完成百分比（月报中累计上报产值/项目合同金额）
//                List<Long> ids = new ArrayList<Long>(Collections.singleton(weekReport.getProjectId()));
                    ProjectBasicResponse project = progressProjectRepository.getProject(weekReport.getProjectId());
                    if (null != project) {
                        // 获取项目合同金额
                        progressEntity.setPercentage("0");
                        if (ObjectUtils.isNotNull(project.getContractCost())) {
                            if (project.getContractCost().intValue() != 0) {
                                Integer accuSum = accumulationOutputSum + weekReport.getReportOutputValue().intValue();
                                Integer costSum = project.getContractCost().intValue();
                                DecimalFormat df = new DecimalFormat("0");
                                String num = df.format(((float) accuSum / costSum) * 100);
                                progressEntity.setPercentage(num);
                            }
                        }
                    }
                    // 查询 里程碑进度状态(0、滞后  1、正常)（有一个滞后就是滞后） 关键任务进度状态(0、滞后  1、正常)（有一个滞后就是滞后）
                    Integer milestone = projectScheduleDetaillMapper.findMilestone(progressEntity);
                    if (milestone == 0) {
                        progressEntity.setMilestoneProgressStatus(1);
                    } else {
                        progressEntity.setMilestoneProgressStatus(0);
                    }
                    Integer taskSum = projectScheduleDetaillMapper.findTask(progressEntity);
                    if (taskSum == 0) {
                        progressEntity.setTaskProgressStatus(1);
                    } else {
                        progressEntity.setTaskProgressStatus(0);
                    }
                    progressEntity.setUpdateDate(LocalDate.parse(updateDate, ISO_DATE));
                    progressMapper.updateById(progressEntity);
                }
            }
        }
    }

    @Override
    public Page<ProgressReport> getProgressWeekReportList(ProgressReportListQuery progressReportListQuery) {
        Page<ProgressReportEntity> progressReportEntityPage = new Page<>(progressReportListQuery.getOffset(), progressReportListQuery.getPageSize());
        ResponseData<List<ProjectBasicResponse>> projectList = new ResponseData<>();
        LambdaQueryWrapper<ProgressReportEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        List<ProjectBasicResponse> list = new ArrayList<>();
//        List<ProjectBasicResponse> allProjectBasicList;
        //如果类型为项目
        if (PROJECT_TYPE.equals(progressReportListQuery.getType())) {
            //对于app端才有 判断 头部id是项目 还是 组织进入 之后选的项目
            if (ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId())) {
                lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId()), ProgressReportEntity::getProjectId, progressReportListQuery.getHrOrganizationId());
            } else {
                lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getProjectId()), ProgressReportEntity::getProjectId, progressReportListQuery.getProjectId());
            }
        } else {
            //判断有无选择主体院
            if (progressReportListQuery.getMainCourtyard() == null) {
                projectList = progressProjectRepository.getProjectList(progressReportListQuery.getHrOrganizationId());
            }
            if (progressReportListQuery.getMainCourtyard() != null) {
                projectList = progressProjectRepository.getProjectList(progressReportListQuery.getMainCourtyard());
            }
            //名称条件搜索
            if (projectList.getData().size() > 0) {
//                list = projectList.getData().stream().filter(v -> {
//                    if (StringUtils.isNotBlank(progressReportListQuery.getName())) {
//                        return v.getProjectName().indexOf(progressReportListQuery.getName()) > -1;
//                    }
//                    return true;
//                }).collect(Collectors.toList());
//                if (CollectionUtils.isNotEmpty(list)) {
                List<Long> projectIds = projectList.getData().stream().map(ProjectBasicResponse::getProjectId).collect(Collectors.toList());
                lambdaQueryWrapper.in(CollectionUtils.isNotEmpty(projectIds), ProgressReportEntity::getProjectId, projectIds);
//                }
            } else {
                return new Page<>();
            }
//            //查出 所有项目  目的 是取主体院名称
//            allProjectBasicList = projectRemoteService.getAllProjectBasicList();
//            //设置 主体院 名称
//            list.forEach(v->{
//                for (ProjectBasicResponse projectBasicResponse: allProjectBasicList){
//                    if (projectBasicResponse.getHrOrganizationId().equals(v.getHrOrganizationId())){
//                        v.setHrOrganizationFullName(projectBasicResponse.getHrOrganizationFullName());
//                    }
//                }
//            });
            lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getProjectId()), ProgressReportEntity::getProjectId, progressReportListQuery.getProjectId());
        }
        lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getConstructionManagerApproval()), ProgressReportEntity::getConstructionManagerApproval, progressReportListQuery.getConstructionManagerApproval());
        String statisticalStartTIme = progressReportListQuery.getStatisticalStartTime() + "-01 00:00:00";
        String statisticalEndTIme = progressReportListQuery.getStatisticalEndTime() + "-31 23:59:59";
        String recordStartTime = progressReportListQuery.getRecordStartTime() + " 00:00:00";
        String recordEndTime = progressReportListQuery.getRecordEndTime() + " 23:59:59";
        lambdaQueryWrapper.ge(ObjectUtils.isNotNull(progressReportListQuery.getStatisticalStartTime()), ProgressReportEntity::getStatisticalStartTime, statisticalStartTIme);
        lambdaQueryWrapper.le(ObjectUtils.isNotNull(progressReportListQuery.getStatisticalEndTime()), ProgressReportEntity::getStatisticalEndTime, statisticalEndTIme);
        lambdaQueryWrapper.ge(ObjectUtils.isNotNull(progressReportListQuery.getRecordStartTime()), ProgressReportEntity::getRecordTime, recordStartTime);
        lambdaQueryWrapper.le(ObjectUtils.isNotNull(progressReportListQuery.getRecordEndTime()), ProgressReportEntity::getRecordTime, recordEndTime);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(progressReportListQuery.getRecordUser()), ProgressReportEntity::getRecordUser, progressReportListQuery.getRecordUser());
        lambdaQueryWrapper.eq(ProgressReportEntity::getType, WEEK_TYPE);
        lambdaQueryWrapper.orderByDesc(ProgressReportEntity::getStatisticalStartTime);
        Page<ProgressReportEntity> progressReportEntityList = progressReportMapper.selectPage(progressReportEntityPage, lambdaQueryWrapper);
        List<ProjectBasicResponse> projectListData = projectList.getData();
        Page<ProgressReport> progressReportList = adapterConverter.progressReportEntityListToProgressReport(progressReportEntityList);
        //设置项目名称
        if (!PROJECT_TYPE.equals(progressReportListQuery.getType()) && projectListData.size() > 0) {
            progressReportList.getRecords().forEach(v -> {
                for (ProjectBasicResponse projectBasicResponse : projectListData) {
                    if (v.getProjectId().equals(projectBasicResponse.getProjectId())) {
                        v.setName(projectBasicResponse.getProjectName());
                        v.setMainCourtyardId(projectBasicResponse.getHrOrganizationId());
                        v.setMainCourtyard(projectBasicResponse.getHrOrganizationFullName());
                        break;
                    }
                }
                List<Person> persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(v.getProjectId()).build());
                if (!persons.isEmpty()) {
                    List<Long> id = persons.stream().distinct().map(Person::getId).collect(Collectors.toList());
                    v.setConstructionMember(id);
                }
            });
        } else if (PROJECT_TYPE.equals(progressReportListQuery.getType())) {
            ProjectBasicResponse project;
            List<Person> persons;
            if (ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId())) {
                project = progressProjectRepository.getProject(progressReportListQuery.getHrOrganizationId());
                persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(progressReportListQuery.getHrOrganizationId()).build());
            } else {
                project = progressProjectRepository.getProject(progressReportListQuery.getProjectId());
                persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(progressReportListQuery.getProjectId()).build());
            }

            progressReportList.getRecords().forEach(v -> {
                v.setName(project.getProjectName());
                v.setMainCourtyard(project.getHrOrganizationFullName());
                v.setMainCourtyardId(project.getHrOrganizationId());
                if (!persons.isEmpty()) {
                    List<Long> id = persons.stream().distinct().map(Person::getId).collect(Collectors.toList());
                    v.setConstructionMember(id);
                }
            });
        }
        return progressReportList;
    }

    @Override
    public Page<ProgressReport> getProgressMonthReportList(ProgressReportListQuery progressReportListQuery) {
        Page<ProgressReportEntity> progressReportEntityPage = new Page<>(progressReportListQuery.getOffset(), progressReportListQuery.getPageSize());
        ResponseData<List<ProjectBasicResponse>> projectList = new ResponseData<>();
        LambdaQueryWrapper<ProgressReportEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
//        List<ProjectBasicResponse> list = new ArrayList<>();
//        List<ProjectBasicResponse> allProjectBasicList;
        if (PROJECT_TYPE.equals(progressReportListQuery.getType())) {
            if (ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId())) {
                lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId()), ProgressReportEntity::getProjectId, progressReportListQuery.getHrOrganizationId());
            } else {
                lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getProjectId()), ProgressReportEntity::getProjectId, progressReportListQuery.getProjectId());
            }
        } else {
            //判断有无主体院
            if (progressReportListQuery.getMainCourtyard() == null) {
                projectList = progressProjectRepository.getProjectList(progressReportListQuery.getHrOrganizationId());
            }
            if (progressReportListQuery.getMainCourtyard() != null) {
                projectList = progressProjectRepository.getProjectList(progressReportListQuery.getMainCourtyard());
            }
            if (projectList.getData().size() > 0) {
//                list = projectList.getData().stream().filter(v -> {
//                    if (StringUtils.isNotBlank(progressReportListQuery.getName())) {
//                        return v.getProjectName().indexOf(progressReportListQuery.getName()) > -1;
//                    }
//                    return true;
//                }).collect(Collectors.toList());
//                if (CollectionUtils.isNotEmpty(list)) {
                List<Long> projectIds = projectList.getData().stream().map(ProjectBasicResponse::getProjectId).collect(Collectors.toList());
                lambdaQueryWrapper.in(CollectionUtils.isNotEmpty(projectIds), ProgressReportEntity::getProjectId, projectIds);
//                }
            } else {
                return new Page<>();
            }
//            //查出 所有项目  目的 是取主体院名称
//            allProjectBasicList = projectRemoteService.getAllProjectBasicList();
//            //设置 主体院 名称
//            list.forEach(v->{
//                for (ProjectBasicResponse projectBasicResponse: allProjectBasicList){
//                    if (projectBasicResponse.getHrOrganizationId().equals(v.getHrOrganizationId())){
//                        v.setHrOrganizationFullName(projectBasicResponse.getHrOrganizationFullName());
//                    }
//                }
//            });
            lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getProjectId()), ProgressReportEntity::getProjectId, progressReportListQuery.getProjectId());
        }
        lambdaQueryWrapper.eq(ObjectUtils.isNotNull(progressReportListQuery.getConstructionManagerApproval()), ProgressReportEntity::getConstructionManagerApproval, progressReportListQuery.getConstructionManagerApproval());
        String statisticalStartTIme = progressReportListQuery.getStatisticalStartTime() + "-01 00:00:00";
        String statisticalEndTIme = progressReportListQuery.getStatisticalEndTime() + "-31 23:59:59";
        String recordStartTime = progressReportListQuery.getRecordStartTime() + " 00:00:00";
        String recordEndTime = progressReportListQuery.getRecordEndTime() + " 23:59:59";
        lambdaQueryWrapper.ge(ObjectUtils.isNotNull(progressReportListQuery.getStatisticalStartTime()), ProgressReportEntity::getStatisticalStartTime, statisticalStartTIme);
        lambdaQueryWrapper.le(ObjectUtils.isNotNull(progressReportListQuery.getStatisticalEndTime()), ProgressReportEntity::getStatisticalEndTime, statisticalEndTIme);
        lambdaQueryWrapper.ge(ObjectUtils.isNotNull(progressReportListQuery.getRecordStartTime()), ProgressReportEntity::getRecordTime, recordStartTime);
        lambdaQueryWrapper.le(ObjectUtils.isNotNull(progressReportListQuery.getRecordEndTime()), ProgressReportEntity::getRecordTime, recordEndTime);
        lambdaQueryWrapper.like(StringUtils.isNotBlank(progressReportListQuery.getRecordUser()), ProgressReportEntity::getRecordUser, progressReportListQuery.getRecordUser());
        lambdaQueryWrapper.eq(ProgressReportEntity::getType, MONTH_TYPE);
        lambdaQueryWrapper.orderByDesc(ProgressReportEntity::getStatisticalStartTime);
        Page<ProgressReportEntity> progressReportEntityList = progressReportMapper.selectPage(progressReportEntityPage, lambdaQueryWrapper);
        List<ProjectBasicResponse> projectListData = projectList.getData();
        Page<ProgressReport> progressReportList = adapterConverter.progressReportEntityListToProgressReport(progressReportEntityList);

        if (!PROJECT_TYPE.equals(progressReportListQuery.getType()) && projectListData.size() > 0) {
            progressReportList.getRecords().forEach(v -> {
                for (ProjectBasicResponse projectBasicResponse : projectListData) {
                    if (v.getProjectId().equals(projectBasicResponse.getProjectId())) {
                        v.setName(projectBasicResponse.getProjectName());
                        v.setMainCourtyard(projectBasicResponse.getHrOrganizationFullName());
                        v.setMainCourtyardId(projectBasicResponse.getHrOrganizationId());
                        break;
                    }
                }
                List<Person> persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(v.getProjectId()).build());
                if (!persons.isEmpty()) {
                    List<Long> id = persons.stream().distinct().map(Person::getId).collect(Collectors.toList());
                    v.setConstructionMember(id);
                }
            });
        } else if (PROJECT_TYPE.equals(progressReportListQuery.getType())) {
            ProjectBasicResponse project;
            List<Person> persons;
            if (ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId())) {
                project = progressProjectRepository.getProject(progressReportListQuery.getHrOrganizationId());
                persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(progressReportListQuery.getHrOrganizationId()).build());
            } else {
                project = progressProjectRepository.getProject(progressReportListQuery.getProjectId());
                persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(progressReportListQuery.getProjectId()).build());
            }

            progressReportList.getRecords().forEach(v -> {
                v.setName(project.getProjectName());
                v.setMainCourtyard(project.getHrOrganizationFullName());
                v.setMainCourtyardId(project.getHrOrganizationId());
                if (!persons.isEmpty()) {
                    List<Long> id = persons.stream().distinct().map(Person::getId).collect(Collectors.toList());
                    v.setConstructionMember(id);
                }
            });
        }

        return progressReportList;
    }

    @Override
    public List<ProgressReportMonthDetailAllResponse> getProgressMonthReportDetailBatch(ProgressReportExportQuery progressReportExportQuery) {
        LambdaQueryWrapper<ProgressReportDetailEntity> lambdaQueryWrapperMilestone, lambdaQueryWrapperKeyTask, lambdaQueryWrapperFirstTask;
        LambdaQueryWrapper<ProgressReportEntity> lambdaQueryWrapperReport;
        List<ProgressReportMonthDetailAllResponse> list = new ArrayList<>();

        lambdaQueryWrapperReport = new LambdaQueryWrapper<>();
        lambdaQueryWrapperReport.in(CollectionUtils.isNotEmpty(progressReportExportQuery.getIds()), ProgressReportEntity::getId, progressReportExportQuery.getIds());
        List<ProgressReportEntity> progressReportEntityList = progressReportMapper.selectList(lambdaQueryWrapperReport);

        lambdaQueryWrapperMilestone = new LambdaQueryWrapper<>();
        lambdaQueryWrapperMilestone.in(CollectionUtils.isNotEmpty(progressReportExportQuery.getIds()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getIds());
        lambdaQueryWrapperMilestone.like(ProgressReportDetailEntity::getType, MILESTONE_TYPE);
        lambdaQueryWrapperMilestone.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> milestoneList = progressReportDetailMapper.selectList(lambdaQueryWrapperMilestone);
        //处理里程碑照片信息
        this.extendPhotoFile(milestoneList);

        lambdaQueryWrapperFirstTask = new LambdaQueryWrapper<>();
        lambdaQueryWrapperFirstTask.in(CollectionUtils.isNotEmpty(progressReportExportQuery.getIds()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getIds());
        lambdaQueryWrapperFirstTask.like(ProgressReportDetailEntity::getType, FIRST_TASK_TYPE);
        lambdaQueryWrapperFirstTask.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> firstList = progressReportDetailMapper.selectList(lambdaQueryWrapperFirstTask);
        this.extendPhotoFile(firstList);


        lambdaQueryWrapperKeyTask = new LambdaQueryWrapper<>();
        lambdaQueryWrapperKeyTask.in(CollectionUtils.isNotEmpty(progressReportExportQuery.getIds()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getIds());
        lambdaQueryWrapperKeyTask.like(ProgressReportDetailEntity::getType, KEY_TASK_TYPE);
        lambdaQueryWrapperKeyTask.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> keyTaskList = progressReportDetailMapper.selectList(lambdaQueryWrapperKeyTask);
        this.extendPhotoFile(keyTaskList);
        //遍历IDS 找出对应的 对象 放入集合
        progressReportExportQuery.getIds().forEach(v -> {
            ProgressReportMonthDetailAllResponse progressReportMonthDetailAllResponse = new ProgressReportMonthDetailAllResponse();
            List<ProgressReportDetailEntity> milestone = new ArrayList<>();
            List<ProgressReportDetailEntity> first = new ArrayList<>();
            List<ProgressReportDetailEntity> keyTask = new ArrayList<>();
            //设置主要详情
            for (ProgressReportEntity progressReportEntity : progressReportEntityList) {
                if (v.equals(progressReportEntity.getId())) {
                    ProgressReportMonthDetailResponse ProgressReportMainList = adapterConverter.progressReportEntityToProgressReportMonthDetailResponse(progressReportEntity);
                    progressReportMonthDetailAllResponse.setProgressReportMainList(ProgressReportMainList);
                }
            }
            //设置里程详情
            for (ProgressReportDetailEntity progressReportDetailEntity : milestoneList) {
                if (v.equals(progressReportDetailEntity.getProgressWeekMonthReportId())) {
                    milestone.add(progressReportDetailEntity);
                }
            }
            List<MilestoneDetailResponse> milestoneDetailResponse = adapterConverter.progressReportDetailEntityToMilestoneDetailResponse(milestone);
            progressReportMonthDetailAllResponse.setMilestoneList(milestoneDetailResponse);
            //设置一级任务详情
            for (ProgressReportDetailEntity progressReportDetailEntity : firstList) {
                if (v.equals(progressReportDetailEntity.getProgressWeekMonthReportId())) {
                    first.add(progressReportDetailEntity);
                }
            }
            List<TaskListResponse> firstListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(first);
            progressReportMonthDetailAllResponse.setFirstTaskList(firstListResponse);
            //设置关键任务详情
            for (ProgressReportDetailEntity progressReportDetailEntity : keyTaskList) {
                if (v.equals(progressReportDetailEntity.getProgressWeekMonthReportId())) {
                    keyTask.add(progressReportDetailEntity);
                }
            }
            List<TaskListResponse> keyTaskListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(keyTask);
            progressReportMonthDetailAllResponse.setKeyTaskList(keyTaskListResponse);
            //设置流程
            List<ProcessTask> processList = processRemoteService.getProcessList(ProcessListQuery.builder()
                    .businessType(CRANE)
                    .businessCode(String.valueOf(v))
                    .processDefinitionKey(PROCESS_CRANE).build());
            List<ProgressProcessResponse> progressProcessResponse = adapterConverter.progressTaskToProcessTaskResponse(processList);
            progressReportMonthDetailAllResponse.setProgressProcess(progressProcessResponse);
            //添加对象
            list.add(progressReportMonthDetailAllResponse);
        });

        return list;
    }

    @Override
    public Integer findMonthNoReport(int monthType, Long projectId) {
        return progressReportMapper.findMonthNoReport(monthType, projectId);
    }

    @Override
    public Page<ProgressReport> getProgressWeekMonthReportListApp(ProgressReportListQuery progressReportListQuery) {
        Page<ProgressReportEntity> progressReportEntityPage = new Page<>(progressReportListQuery.getOffset(), progressReportListQuery.getPageSize());
        ResponseData<List<ProjectBasicResponse>> projectList = new ResponseData<>();
        LambdaQueryWrapper<ProgressReportEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        List<ProjectBasicResponse> list = new ArrayList<>();
        List<ProjectBasicResponse> allProjectBasicList;
        List<Long> projectIds = null;
        ProjectBasicResponse project = null;
        //如果类型为项目
        if (PROJECT_TYPE.equals(progressReportListQuery.getType())) {
            Long id ;
            //对于app端才有 判断 头部id是项目 还是 组织进入 之后选的项目
            if (ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId())) {
                id = progressReportListQuery.getHrOrganizationId();
                project = progressProjectRepository.getProject(id);
            } else {
                id = progressReportListQuery.getProjectId();
                project = progressProjectRepository.getProject(id);
            }
            if (StringUtils.isNotBlank(progressReportListQuery.getName()) && project.getProjectName().indexOf(progressReportListQuery.getName())==-1){
                id = null;
            }
            if ((progressReportListQuery.getReportType() == 1)) {
                Long finalId = id;
                lambdaQueryWrapper.eq(ProgressReportEntity::getType, WEEK_TYPE).eq(ObjectUtils.isNotNull(project.getProjectId()), ProgressReportEntity::getProjectId, project.getProjectId())
                        .eq(ObjectUtils.isNotNull(progressReportListQuery.getConstructionManagerApproval()), ProgressReportEntity::getConstructionManagerApproval, progressReportListQuery.getConstructionManagerApproval())
                        .isNotNull(ProgressReportEntity::getConstructionManagerApproval)
                        .and(i -> i.eq(ObjectUtils.isNotNull(finalId), ProgressReportEntity::getProjectId, finalId).or()
                        .like(StringUtils.isNotBlank(progressReportListQuery.getName()), ProgressReportEntity::getRecordUser, progressReportListQuery.getName()));
            } else {
                Long finalId = id;
                lambdaQueryWrapper.eq(ProgressReportEntity::getType, MONTH_TYPE).eq(ObjectUtils.isNotNull(project.getProjectId()), ProgressReportEntity::getProjectId, project.getProjectId())
                        .eq(ObjectUtils.isNotNull(progressReportListQuery.getConstructionManagerApproval()), ProgressReportEntity::getConstructionManagerApproval, progressReportListQuery.getConstructionManagerApproval())
                        .isNotNull(ProgressReportEntity::getConstructionManagerApproval)
                        .and(i -> i.eq(ObjectUtils.isNotNull(finalId), ProgressReportEntity::getProjectId, finalId).or()
                                .like(StringUtils.isNotBlank(progressReportListQuery.getName()), ProgressReportEntity::getRecordUser, progressReportListQuery.getName()));
            }
        } else {
            //判断有无选择主体院 主体院项目查询
            if (progressReportListQuery.getMainCourtyard() == null) {
                projectList = progressProjectRepository.getProjectList(progressReportListQuery.getHrOrganizationId());
            }
            if (progressReportListQuery.getMainCourtyard() != null) {
                projectList = progressProjectRepository.getProjectList(progressReportListQuery.getMainCourtyard());
            }
            //名称条件搜索
            if (projectList.getData().size() > 0) {
                list = projectList.getData().stream().filter(v -> {
                    if (StringUtils.isNotBlank(progressReportListQuery.getName())) {
                        if (v.getProjectName().indexOf(progressReportListQuery.getName()) > -1) {
                            return true;
                        }
                        return false;
                    }
                    return true;
                }).collect(Collectors.toList());
                if (CollectionUtils.isNotEmpty(list)) {
                    projectIds = list.stream().map(ProjectBasicResponse::getProjectId).collect(Collectors.toList());

                }
            }
            if (projectList.getData().size() == 0 && CollectionUtils.isEmpty(list)) {
                return new Page<>();
            }
            //查出 所有项目  目的 是取主体院名称
            allProjectBasicList = projectRemoteService.getAllProjectBasicList();
            //设置 主体院 名称
            projectList.getData().forEach(v -> {
                for (ProjectBasicResponse projectBasicResponse : allProjectBasicList) {
                    if (projectBasicResponse.getHrOrganizationId().equals(v.getHrOrganizationId())) {
                        v.setHrOrganizationFullName(projectBasicResponse.getHrOrganizationFullName());
                    }
                }
            });
            if ((progressReportListQuery.getReportType() == 1)) {
                List<Long> finalProjectIds = projectIds;
                lambdaQueryWrapper.eq(ProgressReportEntity::getType, WEEK_TYPE).eq(ObjectUtils.isNotNull(progressReportListQuery.getProjectId()), ProgressReportEntity::getProjectId, progressReportListQuery.getProjectId())
                        .eq(ObjectUtils.isNotNull(progressReportListQuery.getConstructionManagerApproval()), ProgressReportEntity::getConstructionManagerApproval, progressReportListQuery.getConstructionManagerApproval())
                        .isNotNull(ProgressReportEntity::getConstructionManagerApproval)
                        .and(i -> i.in(CollectionUtils.isNotEmpty(finalProjectIds), ProgressReportEntity::getProjectId, finalProjectIds).or()
                                .like(StringUtils.isNotBlank(progressReportListQuery.getName()), ProgressReportEntity::getRecordUser, progressReportListQuery.getName()));
            } else {
                List<Long> finalProjectIds = projectIds;
                lambdaQueryWrapper.eq(ProgressReportEntity::getType, MONTH_TYPE).eq(ObjectUtils.isNotNull(progressReportListQuery.getProjectId()), ProgressReportEntity::getProjectId, progressReportListQuery.getProjectId())
                        .eq(ObjectUtils.isNotNull(progressReportListQuery.getConstructionManagerApproval()), ProgressReportEntity::getConstructionManagerApproval, progressReportListQuery.getConstructionManagerApproval())
                        .isNotNull(ProgressReportEntity::getConstructionManagerApproval)
                        .and(i -> i.in(CollectionUtils.isNotEmpty(finalProjectIds), ProgressReportEntity::getProjectId, finalProjectIds).or()
                                .like(StringUtils.isNotBlank(progressReportListQuery.getName()), ProgressReportEntity::getRecordUser, progressReportListQuery.getName()));
            }
        }
        lambdaQueryWrapper.orderByDesc(ProgressReportEntity::getStatisticalStartTime);
        Page<ProgressReportEntity> progressReportEntityList = progressReportMapper.selectPage(progressReportEntityPage, lambdaQueryWrapper);
        List<ProjectBasicResponse> projectListData = projectList.getData();

        Page<ProgressReport> progressReportList = adapterConverter.progressReportEntityListToProgressReport(progressReportEntityList);
        //设置项目名称  施工经理
        if (!PROJECT_TYPE.equals(progressReportListQuery.getType()) && projectListData.size() > 0) {
            progressReportList.getRecords().forEach(v -> {
                for (ProjectBasicResponse projectBasicResponse : projectListData) {
                    if (v.getProjectId().equals(projectBasicResponse.getProjectId())) {
                        v.setName(projectBasicResponse.getProjectName());
                        v.setMainCourtyard(projectBasicResponse.getHrOrganizationFullName());
                        v.setMainCourtyardId(projectBasicResponse.getHrOrganizationId());
                        break;
                    }
                }
                List<Person> persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(v.getProjectId()).build());
                if (!persons.isEmpty()) {
                    List<Long> id = persons.stream().distinct().map(Person::getId).collect(Collectors.toList());
                    v.setConstructionMember(id);
                }
            });
        } else if (PROJECT_TYPE.equals(progressReportListQuery.getType())) {
            List<Person> persons;
            if (ObjectUtils.isNotNull(progressReportListQuery.getHrOrganizationId())) {
                persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(progressReportListQuery.getHrOrganizationId()).build());
            } else {
                persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(progressReportListQuery.getProjectId()).build());
            }

            ProjectBasicResponse finalProject = project;
            progressReportList.getRecords().forEach(v -> {
                v.setName(finalProject.getProjectName());
                v.setMainCourtyard(finalProject.getHrOrganizationFullName());
                v.setMainCourtyardId(finalProject.getHrOrganizationId());
                if (!persons.isEmpty()) {
                    List<Long> id = persons.stream().distinct().map(Person::getId).collect(Collectors.toList());
                    v.setConstructionMember(id);
                }
            });
        }
        return progressReportList;
    }

    @Override
    public List<ProjectScheduleDetail> getProjectScheduleDetailTaskList(ProgressWeekMonthReportCommand progressWeekMonthReportCommand) {
        Long projectId = progressWeekMonthReportCommand.getProjectId();
        LambdaQueryWrapper<ProgressEntity> progressEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        progressEntityLambdaQueryWrapper.eq(ProgressEntity ::getProjectId,projectId);
        ProgressEntity progress = progressMapper.selectOne(progressEntityLambdaQueryWrapper);
        Long id = progress.getId();
        LambdaQueryWrapper<ProgressDetailEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProgressDetailEntity ::getProjectId,projectId);
        lambdaQueryWrapper.eq(ProgressDetailEntity ::getProjectScheduleId,id);
        if(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getTaskType())){
            lambdaQueryWrapper.like(ProgressDetailEntity ::getType,progressWeekMonthReportCommand.getTaskType());
        }
        lambdaQueryWrapper.orderByAsc(ProgressDetailEntity::getNamePrefix);
        List<ProgressDetailEntity> list = projectScheduleDetaillMapper.selectList(lambdaQueryWrapper);
        return adapterConverter.progressDetailEntityToProjectScheduleDetail(list);
    }

    @Override
    public List<Long> getConstructionMemberByProjectId(Long projectId) {
        List<Person> persons = personRepository.getPersonList(PersonQuery.builder().projectJob(messageNotifyProjectManagerRole).projectId(projectId).build());
        if (!persons.isEmpty()) {
            List<Long> id = persons.stream().distinct().map(Person::getId).collect(Collectors.toList());
            return id;
        }else{
            return new ArrayList<>();
        }
    }


    @Override
    public ProgressReportMonthDetailAllResponse getProgressMonthReportDetail(ProgressReportExportQuery progressReportExportQuery) {
        LambdaQueryWrapper<ProgressEntity> progressEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
        progressEntityLambdaQueryWrapper.eq(ProgressEntity ::getProjectId,progressReportExportQuery.getProjectId());
        ProgressEntity progress = progressMapper.selectOne(progressEntityLambdaQueryWrapper);
        Long id = progress.getId();

        LambdaQueryWrapper<ProgressReportDetailEntity> lambdaQueryWrapperMilestone, lambdaQueryWrapperKeyTask, lambdaQueryWrapperFirstTask;
        LambdaQueryWrapper<ProgressReportEntity> lambdaQueryWrapperReport;
        ProjectBasicResponse project = progressProjectRepository.getProject(progressReportExportQuery.getProjectId());

        lambdaQueryWrapperReport = new LambdaQueryWrapper<>();
        lambdaQueryWrapperReport.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportEntity::getId, progressReportExportQuery.getId());
        ProgressReportEntity progressReportEntity = progressReportMapper.selectOne(lambdaQueryWrapperReport);
        ProgressReportMonthDetailResponse ProgressReportMainList = adapterConverter.progressReportEntityToProgressReportMonthDetailResponse(progressReportEntity);
        ProgressReportMainList.setName(project.getProjectName());
        ProgressReportMainList.setContractCost(project.getContractCost()==null? BigDecimal.valueOf(0.0) : project.getContractCost());

        /*lambdaQueryWrapperMilestone = new LambdaQueryWrapper<>();
        lambdaQueryWrapperMilestone.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        lambdaQueryWrapperMilestone.like(ProgressReportDetailEntity::getType, MILESTONE_TYPE);
        lambdaQueryWrapperMilestone.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> milestoneList = progressReportDetailMapper.selectList(lambdaQueryWrapperMilestone);*/
        //里程碑
        LambdaQueryWrapper<ProgressDetailEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProgressDetailEntity ::getProjectId,progressReportExportQuery.getProjectId());
        lambdaQueryWrapper.eq(ProgressDetailEntity ::getProjectScheduleId,id);
        lambdaQueryWrapper.like(ProgressDetailEntity ::getType,MILESTONE_TYPE);
        lambdaQueryWrapper.orderByAsc(ProgressDetailEntity ::getSortIndex);
        List<ProgressDetailEntity> milestone = projectScheduleDetaillMapper.selectList(lambdaQueryWrapper);
        List<ProgressReportDetailEntity> milestoneList = new ArrayList<>();
        for(ProgressDetailEntity v : milestone){
            String namePrefix = v.getNamePrefix();
            String name = v.getName();
            String type = v.getType();
            lambdaQueryWrapperMilestone = new LambdaQueryWrapper<>();
            lambdaQueryWrapperMilestone.eq(ProgressReportDetailEntity ::getNamePrefix,namePrefix);
            lambdaQueryWrapperMilestone.eq(ProgressReportDetailEntity ::getName,name);
            lambdaQueryWrapperMilestone.eq(ProgressReportDetailEntity ::getType,type);
            lambdaQueryWrapperMilestone.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
            ProgressReportDetailEntity entity = progressReportDetailMapper.selectOne(lambdaQueryWrapperMilestone);
            ProgressReportDetailEntity detail =  adapterConverter.pogressDetailToProgressReportDetailEntity(v);
            if(entity != null){
                detail.setProgressWeekMonthReportId(entity.getProgressWeekMonthReportId());
                detail.setRealStartTime(entity.getRealStartTime());
                detail.setRealEndTime(entity.getRealEndTime());
                detail.setPercentage(entity.getPercentage());
            }
            milestoneList.add(detail);
        }
        //处理里程碑照片信息
        this.extendPhotoFile(milestoneList);
        List<MilestoneDetailResponse> milestoneDetailResponse = adapterConverter.progressReportDetailEntityToMilestoneDetailResponse(milestoneList);

        /*lambdaQueryWrapperFirstTask = new LambdaQueryWrapper<>();
        lambdaQueryWrapperFirstTask.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        lambdaQueryWrapperFirstTask.like(ProgressReportDetailEntity::getType, FIRST_TASK_TYPE);
        lambdaQueryWrapperFirstTask.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> firstList = progressReportDetailMapper.selectList(lambdaQueryWrapperFirstTask);
        this.extendPhotoFile(firstList);
        List<TaskListResponse> firstListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(firstList);*/

        LambdaQueryWrapper<ProgressReportDetailEntity> milestonesEntity = new LambdaQueryWrapper<>();
        milestonesEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        milestonesEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        milestonesEntity.like(ProgressReportDetailEntity::getType, MILESTONES_TYPE);
        milestonesEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> milestones = progressReportDetailMapper.selectList(milestonesEntity);
        LambdaQueryWrapper<ProgressReportDetailEntity> keyTaskEntity = new LambdaQueryWrapper<>();
        keyTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        keyTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        keyTaskEntity.like(ProgressReportDetailEntity::getType, KEY_TYPE);
        keyTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> keyTasks = progressReportDetailMapper.selectList(keyTaskEntity);


        LambdaQueryWrapper<ProgressReportDetailEntity> oneTaskEntity = new LambdaQueryWrapper<>();
        oneTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        oneTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        oneTaskEntity.like(ProgressReportDetailEntity::getType, ONE_TYPE);
        oneTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> oneTasks = progressReportDetailMapper.selectList(oneTaskEntity);

        LambdaQueryWrapper<ProgressReportDetailEntity> twoTaskEntity = new LambdaQueryWrapper<>();
        twoTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        twoTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        twoTaskEntity.like(ProgressReportDetailEntity::getType, TWO_TYPE);
        twoTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> twoTasks = progressReportDetailMapper.selectList(twoTaskEntity);

        LambdaQueryWrapper<ProgressReportDetailEntity> taskEntity = new LambdaQueryWrapper<>();
        taskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        taskEntity.eq( ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        taskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> task = progressReportDetailMapper.selectList(taskEntity);

        oneTasks.addAll(task);

        oneTasks.addAll(milestones);
        oneTasks.addAll(keyTasks);
        oneTasks.addAll(twoTasks);

        Set<ProgressReportDetailEntity> hashSet = new HashSet<>(oneTasks);
        List<ProgressReportDetailEntity> firstList = new ArrayList(hashSet);
        Collections.sort(firstList,Comparator.comparing(ProgressReportDetailEntity::getNamePrefix));
        this.extendPhotoFile(firstList);
        List<TaskListResponse> firstListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(firstList);




        /*lambdaQueryWrapperKeyTask = new LambdaQueryWrapper<>();
        lambdaQueryWrapperKeyTask.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        lambdaQueryWrapperKeyTask.like(ProgressReportDetailEntity::getType, KEY_TASK_TYPE);
        lambdaQueryWrapperKeyTask.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> keyTaskList = progressReportDetailMapper.selectList(lambdaQueryWrapperKeyTask);*/

        //关键任务
        lambdaQueryWrapper = new LambdaQueryWrapper<>();
        lambdaQueryWrapper.eq(ProgressDetailEntity ::getProjectId,progressReportExportQuery.getProjectId());
        lambdaQueryWrapper.eq(ProgressDetailEntity ::getProjectScheduleId,id);
        lambdaQueryWrapper.like(ProgressDetailEntity ::getType,KEY_TASK_TYPE);
        lambdaQueryWrapper.orderByAsc(ProgressDetailEntity ::getSortIndex);
        List<ProgressDetailEntity> keyList = projectScheduleDetaillMapper.selectList(lambdaQueryWrapper);
        List<ProgressReportDetailEntity> keyTaskList = new ArrayList<>();
        for(ProgressDetailEntity v : keyList){
            String namePrefix = v.getNamePrefix();
            String name = v.getName();
            String type = v.getType();
            lambdaQueryWrapperKeyTask = new LambdaQueryWrapper<>();
            lambdaQueryWrapperKeyTask.eq(ProgressReportDetailEntity ::getNamePrefix,namePrefix);
            lambdaQueryWrapperKeyTask.eq(ProgressReportDetailEntity ::getName,name);
            lambdaQueryWrapperKeyTask.eq(ProgressReportDetailEntity ::getType,type);
            lambdaQueryWrapperKeyTask.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
            ProgressReportDetailEntity entity = progressReportDetailMapper.selectOne(lambdaQueryWrapperKeyTask);
            ProgressReportDetailEntity detail =  adapterConverter.pogressDetailToProgressReportDetailEntity(v);
            if(entity != null){
                detail.setProgressWeekMonthReportId(entity.getProgressWeekMonthReportId());
                detail.setRealStartTime(entity.getRealStartTime());
                detail.setRealEndTime(entity.getRealEndTime());
                detail.setPercentage(entity.getPercentage());
            }
            keyTaskList.add(detail);
        }

        this.extendPhotoFile(keyTaskList);
        List<TaskListResponse> keyTaskListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(keyTaskList);

        List<ProcessTask> processList = processRemoteService.getProcessList(ProcessListQuery.builder()
                .businessType(WEEK_MONTH)
                .businessCode(String.valueOf(progressReportExportQuery.getId()))
                .processDefinitionKey(PROCESS_REPORT).build());
        List<ProgressProcessResponse> progressProcessResponse = adapterConverter.progressTaskToProcessTaskResponse(processList);

        ProgressReportMonthDetailAllResponse progressReportMonthDetailAllResponse = new ProgressReportMonthDetailAllResponse();
        progressReportMonthDetailAllResponse.setProgressReportMainList(ProgressReportMainList);
        progressReportMonthDetailAllResponse.setKeyTaskList(keyTaskListResponse);
        progressReportMonthDetailAllResponse.setFirstTaskList(firstListResponse);
        progressReportMonthDetailAllResponse.setMilestoneList(milestoneDetailResponse);
        progressReportMonthDetailAllResponse.setProgressProcess(progressProcessResponse);


        return progressReportMonthDetailAllResponse;
    }

    //获取照片文件并填充
    private void extendPhotoFile(List<ProgressReportDetailEntity> progressReportDetailEntities) {
        List<String> ids = new ArrayList<>();
        if (CollectionUtils.isEmpty(progressReportDetailEntities)){
            return;
        }
        //id拼接
        progressReportDetailEntities.forEach(v -> {
            if(ObjectUtils.isNotNull(v.getProgressWeekMonthReportId())){
                String id = v.getId().toString() + v.getProgressWeekMonthReportId().toString();
                ids.add(id);
            }
        });

        LambdaQueryWrapper<ProgressAttachmentImageEntity> lambdaQueryWrapperImage = new LambdaQueryWrapper<>();
        lambdaQueryWrapperImage.in(CollectionUtils.isNotEmpty(ids), ProgressAttachmentImageEntity::getProgressWeekMonthDetailId, ids);
        List<ProgressAttachmentImageEntity> progressAttachmentImageEntities = progressAttachmentImageMapper.selectList(lambdaQueryWrapperImage);
        if (progressAttachmentImageEntities.size() > 0) {
            List<String> signKeys = progressAttachmentImageEntities.stream().map(ProgressAttachmentImageEntity::getSignKey).collect(Collectors.toList());
            List<File> fileList = fileRepository.getFileList(FileQuery.builder().signKeys(signKeys).build());
            List<FileResponse> fileResponseList = new ArrayList<>();
            fileList.forEach(v -> {
                fileResponseList.add(FileResponse.builder()
                        .name(v.getName())
                        .extName(v.getExtName())
                        .signKey(v.getSignKey())
                        .url(v.getUrlOut())
                        .build());
            });
            for (ProgressReportDetailEntity progressReportDetailEntity : progressReportDetailEntities) {
                List<FileResponse> photoFileList = new ArrayList<>();
                if(ObjectUtils.isNotNull(progressReportDetailEntity.getProgressWeekMonthReportId())){
                    String id = progressReportDetailEntity.getId().toString() + progressReportDetailEntity.getProgressWeekMonthReportId().toString();
                    for (ProgressAttachmentImageEntity progressAttachmentImage : progressAttachmentImageEntities) {
                        if (id.equals(progressAttachmentImage.getProgressWeekMonthDetailId())) {
                            for (FileResponse file : fileResponseList) {
                                if (progressAttachmentImage.getSignKey().equals(file.getSignKey())) {
                                    photoFileList.add(file);
                                    break;
                                }
                            }
                        }
                    }
                }
                progressReportDetailEntity.setPhotoFile(photoFileList);
            }
        }
    }


    @Override
    public ProgressReportWeekDetailAllResponse getProgressWeekReportDetail(ProgressReportExportQuery progressReportExportQuery) {
        LambdaQueryWrapper<ProgressReportDetailEntity> lambdaQueryWrapperMilestone, lambdaQueryWrapperKeyTask, lambdaQueryWrapperFirstTask;
        LambdaQueryWrapper<ProgressReportEntity> lambdaQueryWrapperReport;
        ProjectBasicResponse project = progressProjectRepository.getProject(progressReportExportQuery.getProjectId());

        lambdaQueryWrapperReport = new LambdaQueryWrapper<>();
        lambdaQueryWrapperReport.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportEntity::getId, progressReportExportQuery.getId());
        ProgressReportEntity progressReportEntityList = progressReportMapper.selectOne(lambdaQueryWrapperReport);
        ProgressReportWeekDetailResponse ProgressReportMainList = adapterConverter.progressReportEntityToProgressReportWeekDetailResponse(progressReportEntityList);
        ProgressReportMainList.setName(project.getProjectName());

        lambdaQueryWrapperMilestone = new LambdaQueryWrapper<>();
        lambdaQueryWrapperMilestone.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        lambdaQueryWrapperMilestone.like(ProgressReportDetailEntity::getType, MILESTONE_TYPE);
        lambdaQueryWrapperMilestone.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> milestoneList = progressReportDetailMapper.selectList(lambdaQueryWrapperMilestone);
        this.extendPhotoFile(milestoneList);
        List<MilestoneDetailResponse> milestoneDetailResponse = adapterConverter.progressReportDetailEntityToMilestoneDetailResponse(milestoneList);

        /*lambdaQueryWrapperFirstTask = new LambdaQueryWrapper<>();
        lambdaQueryWrapperFirstTask.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        lambdaQueryWrapperFirstTask.like(ProgressReportDetailEntity::getType, FIRST_TASK_TYPE);
        lambdaQueryWrapperFirstTask.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> firstList = progressReportDetailMapper.selectList(lambdaQueryWrapperFirstTask);
        this.extendPhotoFile(firstList);
        List<TaskListResponse> firstListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(firstList);*/
        LambdaQueryWrapper<ProgressReportDetailEntity> milestonesEntity = new LambdaQueryWrapper<>();
        milestonesEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        milestonesEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        milestonesEntity.like(ProgressReportDetailEntity::getType, MILESTONES_TYPE);
        milestonesEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> milestones = progressReportDetailMapper.selectList(milestonesEntity);
        LambdaQueryWrapper<ProgressReportDetailEntity> keyTaskEntity = new LambdaQueryWrapper<>();
        keyTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        keyTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        keyTaskEntity.like(ProgressReportDetailEntity::getType, KEY_TYPE);
        keyTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> keyTasks = progressReportDetailMapper.selectList(keyTaskEntity);
        LambdaQueryWrapper<ProgressReportDetailEntity> oneTaskEntity = new LambdaQueryWrapper<>();
        oneTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        oneTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        oneTaskEntity.like(ProgressReportDetailEntity::getType, ONE_TYPE);
        oneTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> oneTasks = progressReportDetailMapper.selectList(oneTaskEntity);
        LambdaQueryWrapper<ProgressReportDetailEntity> twoTaskEntity = new LambdaQueryWrapper<>();
        twoTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        twoTaskEntity.eq(ObjectUtils.isNotNull(progressReportExportQuery.getProjectId()), ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        twoTaskEntity.like(ProgressReportDetailEntity::getType, TWO_TYPE);
        twoTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> twoTasks = progressReportDetailMapper.selectList(twoTaskEntity);

        LambdaQueryWrapper<ProgressReportDetailEntity> taskEntity = new LambdaQueryWrapper<>();
        taskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        taskEntity.eq( ProgressReportDetailEntity::getProjectId, progressReportExportQuery.getProjectId());
        taskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> task = progressReportDetailMapper.selectList(taskEntity);

        oneTasks.addAll(task);
        oneTasks.addAll(milestones);
        oneTasks.addAll(keyTasks);
        oneTasks.addAll(twoTasks);

        Set<ProgressReportDetailEntity> hashSet = new HashSet<>(oneTasks);
        List firstList = new ArrayList(hashSet);
        this.extendPhotoFile(firstList);
        List<TaskListResponse> firstListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(firstList);


        lambdaQueryWrapperKeyTask = new LambdaQueryWrapper<>();
        lambdaQueryWrapperKeyTask.eq(ObjectUtils.isNotNull(progressReportExportQuery.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportExportQuery.getId());
        lambdaQueryWrapperKeyTask.like(ProgressReportDetailEntity::getType, KEY_TASK_TYPE);
        lambdaQueryWrapperKeyTask.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> keyTaskList = progressReportDetailMapper.selectList(lambdaQueryWrapperKeyTask);
        this.extendPhotoFile(keyTaskList);
        List<TaskListResponse> keyTaskListResponse = adapterConverter.progressReportDetailEntityToTaskListResponse(keyTaskList);

        List<ProcessTask> processList = processRemoteService.getProcessList(ProcessListQuery.builder()
                .businessType(WEEK_MONTH)
                .businessCode(String.valueOf(progressReportExportQuery.getId()))
                .processDefinitionKey(PROCESS_REPORT).build());
        List<ProgressProcessResponse> progressProcessResponse = adapterConverter.progressTaskToProcessTaskResponse(processList);

        ProgressReportWeekDetailAllResponse progressReportWeekDetailAllResponse = new ProgressReportWeekDetailAllResponse();
        progressReportWeekDetailAllResponse.setProgressReportMainList(ProgressReportMainList);
        progressReportWeekDetailAllResponse.setKeyTaskList(keyTaskListResponse);
        progressReportWeekDetailAllResponse.setFirstTaskList(firstListResponse);
        progressReportWeekDetailAllResponse.setMilestoneList(milestoneDetailResponse);
        progressReportWeekDetailAllResponse.setProgressProcess(progressProcessResponse);

        return progressReportWeekDetailAllResponse;
    }

    private List<ProgressReportDetailEntity> getDataByLastTime(Long projectId,Long type,String startTime,String endTime,Long ProgressEntityId){
        // 根据项目 id 主键id 获取主表数据已经 详情数据
        LambdaQueryWrapper<ProgressReportEntity> progressReportEntity = new LambdaQueryWrapper<>();
        progressReportEntity.eq( ProgressReportEntity::getProjectId, projectId);
        progressReportEntity.eq( ProgressReportEntity::getType, type);
        progressReportEntity.eq(ProgressReportEntity ::getStatisticalStartTime,startTime);
        progressReportEntity.eq(ProgressReportEntity ::getStatisticalEndTime,endTime);
        ProgressReportEntity progressReport = progressReportMapper.selectOne(progressReportEntity);
        if(progressReport == null){
            return new ArrayList<>();
        }
        // 获取项目金额
//        ProjectBasicResponse project = progressProjectRepository.getProject(progressReport.getProjectId());
        LambdaQueryWrapper<ProgressReportDetailEntity> milestonesEntity = new LambdaQueryWrapper<>();
        milestonesEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReport.getId());
        milestonesEntity.eq( ProgressReportDetailEntity::getProjectId, projectId);
        milestonesEntity.like(ProgressReportDetailEntity::getType, MILESTONES_TYPE);
        milestonesEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> milestones = progressReportDetailMapper.selectList(milestonesEntity);
        LambdaQueryWrapper<ProgressReportDetailEntity> keyTaskEntity = new LambdaQueryWrapper<>();
        keyTaskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReport.getId());
        keyTaskEntity.eq(ProgressReportDetailEntity::getProjectId, projectId);
        keyTaskEntity.like(ProgressReportDetailEntity::getType, KEY_TYPE);
        keyTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> keyTasks = progressReportDetailMapper.selectList(keyTaskEntity);


        LambdaQueryWrapper<ProgressReportDetailEntity> oneTaskEntity = new LambdaQueryWrapper<>();
        oneTaskEntity.eq(ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReport.getId());
        oneTaskEntity.eq(ProgressReportDetailEntity::getProjectId, projectId);
        oneTaskEntity.like(ProgressReportDetailEntity::getType, ONE_TYPE);
        oneTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> oneTasks = progressReportDetailMapper.selectList(oneTaskEntity);

        LambdaQueryWrapper<ProgressReportDetailEntity> twoTaskEntity = new LambdaQueryWrapper<>();
        twoTaskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReport.getId());
        twoTaskEntity.eq( ProgressReportDetailEntity::getProjectId, projectId);
        twoTaskEntity.like(ProgressReportDetailEntity::getType, TWO_TYPE);
        twoTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> twoTasks = progressReportDetailMapper.selectList(twoTaskEntity);

        LambdaQueryWrapper<ProgressReportDetailEntity> taskEntity = new LambdaQueryWrapper<>();
        taskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReport.getId());
        taskEntity.eq( ProgressReportDetailEntity::getProjectId, projectId);
        taskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
        List<ProgressReportDetailEntity> task = progressReportDetailMapper.selectList(taskEntity);

        oneTasks.addAll(task);
        oneTasks.addAll(milestones);
        oneTasks.addAll(keyTasks);
        oneTasks.addAll(twoTasks);


        Set<ProgressReportDetailEntity> hashSet = new HashSet<>(oneTasks);
        List<ProgressReportDetailEntity> newList = new ArrayList(hashSet);
        for(ProgressReportDetailEntity entity : newList) {
            LambdaQueryWrapper<ProgressDetailEntity> progressDetailEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
            progressDetailEntityLambdaQueryWrapper.eq(ProgressDetailEntity::getProjectId, projectId);
            progressDetailEntityLambdaQueryWrapper.eq(ProgressDetailEntity::getProjectScheduleId, ProgressEntityId);
            progressDetailEntityLambdaQueryWrapper.eq(ObjectUtils.isNotNull(entity.getParentName()),ProgressDetailEntity::getParentName, entity.getParentName());
            progressDetailEntityLambdaQueryWrapper.eq(ProgressDetailEntity::getNamePrefix, entity.getNamePrefix());
            progressDetailEntityLambdaQueryWrapper.eq(ProgressDetailEntity::getName, entity.getName());
            ProgressDetailEntity progressDetailEntity = projectScheduleDetaillMapper.selectOne(progressDetailEntityLambdaQueryWrapper);
            if(progressDetailEntity != null  ){
                if((progressDetailEntity.getCompletion() != null && progressDetailEntity.getCompletion() == 1) || (progressDetailEntity.getPercentage() != null && progressDetailEntity.getPercentage().equals("100"))){
                    entity.setEditFlag(0);
                }else{
                    entity.setEditFlag(1);
                }
            }else{
                entity.setEditFlag(1);
            }
            LambdaQueryWrapper<ProgressAttachmentImageEntity> progressAttachmentImageQueryWrapper = new LambdaQueryWrapper<>();
            progressAttachmentImageQueryWrapper.eq(ProgressAttachmentImageEntity::getProgressWeekMonthDetailId, entity.getId().toString() + entity.getProgressWeekMonthReportId().toString());
            List<ProgressAttachmentImageEntity> attachmentImageEntityList = progressAttachmentImageMapper.selectList(progressAttachmentImageQueryWrapper);
            entity.setProgressAttachmentImageEntityList(attachmentImageEntityList);
        }
        return newList;
    }

    @Override
    public WeekMonthReportEidt monthWeekReportEidtDetail(ProgressWeekMonthReportCommand progressWeekMonthReportCommand) {
        // 根据项目 id 主键id 获取主表数据已经 详情数据
        LambdaQueryWrapper<ProgressReportEntity> progressReportEntity = new LambdaQueryWrapper<>();
        progressReportEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getProjectId()), ProgressReportEntity::getProjectId, progressWeekMonthReportCommand.getProjectId());
        progressReportEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getId()), ProgressReportEntity::getId, progressWeekMonthReportCommand.getId());
        ProgressReportEntity progressReport = progressReportMapper.selectOne(progressReportEntity);
        // 获取项目金额
//        ProjectBasicResponse project = progressProjectRepository.getProject(progressReport.getProjectId());
        LambdaQueryWrapper<ProgressReportDetailEntity> milestonesEntity = new LambdaQueryWrapper<>();
        milestonesEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressWeekMonthReportCommand.getId());
        milestonesEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getProjectId()), ProgressReportDetailEntity::getProjectId, progressWeekMonthReportCommand.getProjectId());
        milestonesEntity.like(ProgressReportDetailEntity::getType, MILESTONES_TYPE);
        milestonesEntity.orderByAsc(ProgressReportDetailEntity::getNamePrefix);
        List<ProgressReportDetailEntity> milestones = progressReportDetailMapper.selectList(milestonesEntity);
        LambdaQueryWrapper<ProgressReportDetailEntity> keyTaskEntity = new LambdaQueryWrapper<>();
        keyTaskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressWeekMonthReportCommand.getId());
        keyTaskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getProjectId()), ProgressReportDetailEntity::getProjectId, progressWeekMonthReportCommand.getProjectId());
        keyTaskEntity.like(ProgressReportDetailEntity::getType, KEY_TYPE);
        keyTaskEntity.orderByAsc(ProgressReportDetailEntity::getNamePrefix);
        List<ProgressReportDetailEntity> keyTasks = progressReportDetailMapper.selectList(keyTaskEntity);


        LambdaQueryWrapper<ProgressReportDetailEntity> oneTaskEntity = new LambdaQueryWrapper<>();
        oneTaskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressWeekMonthReportCommand.getId());
        oneTaskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getProjectId()), ProgressReportDetailEntity::getProjectId, progressWeekMonthReportCommand.getProjectId());
        oneTaskEntity.like(ProgressReportDetailEntity::getType, ONE_TYPE);
        oneTaskEntity.orderByAsc(ProgressReportDetailEntity::getNamePrefix);
        List<ProgressReportDetailEntity> oneTasks = progressReportDetailMapper.selectList(oneTaskEntity);

        LambdaQueryWrapper<ProgressReportDetailEntity> twoTaskEntity = new LambdaQueryWrapper<>();
        twoTaskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressWeekMonthReportCommand.getId());
        twoTaskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getProjectId()), ProgressReportDetailEntity::getProjectId, progressWeekMonthReportCommand.getProjectId());
        twoTaskEntity.like(ProgressReportDetailEntity::getType, TWO_TYPE);
        twoTaskEntity.orderByAsc(ProgressReportDetailEntity::getNamePrefix);
        List<ProgressReportDetailEntity> twoTasks = progressReportDetailMapper.selectList(twoTaskEntity);

        LambdaQueryWrapper<ProgressReportDetailEntity> taskEntity = new LambdaQueryWrapper<>();
        taskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getId()), ProgressReportDetailEntity::getProgressWeekMonthReportId, progressWeekMonthReportCommand.getId());
        taskEntity.eq(ObjectUtils.isNotNull(progressWeekMonthReportCommand.getProjectId()), ProgressReportDetailEntity::getProjectId, progressWeekMonthReportCommand.getProjectId());
        taskEntity.orderByAsc(ProgressReportDetailEntity::getNamePrefix);
        List<ProgressReportDetailEntity> task = progressReportDetailMapper.selectList(taskEntity);
        //oneTasks.addAll(task);
        //oneTasks.addAll(milestones);
        //oneTasks.addAll(keyTasks);
        //oneTasks.addAll(twoTasks);


        /*Set<ProgressReportDetailEntity> hashSet = new HashSet<>(oneTasks);
        List newList = new ArrayList(hashSet);*/

        //2024-07-09 修改，项目周末任务完成情况单独提取出来 -- start
        /*LambdaQueryWrapper<ProjectTaskEntity> taskEntityLambdaQuery = new LambdaQueryWrapper<>();
        taskEntityLambdaQuery.eq(ProjectTaskEntity ::getType,progressWeekMonthReportCommand.getType());
        taskEntityLambdaQuery.eq(ProjectTaskEntity ::getProjectId,progressReport.getProjectId());
        List<ProjectTaskEntity> taskList = projectTaskMapper.selectList(taskEntityLambdaQuery);
        List<ProgressReportDetailEntity> oneTasks = new ArrayList<>();
        if(taskList.size() > 0){
            List<Long> taskIds = new ArrayList<>();
            taskList.forEach(task ->{
                taskIds.add(task.getScheduleDetailId());
            });
            LambdaQueryWrapper<ProgressDetailEntity> oneTaskEntity = new LambdaQueryWrapper<>();
            oneTaskEntity.in(ProgressDetailEntity ::getId,taskIds);
            oneTaskEntity.orderByAsc(ProgressDetailEntity::getSortIndex);
            List<ProgressDetailEntity> progressDetailEntity = projectScheduleDetaillMapper.selectList(oneTaskEntity);
            oneTasks = progressReportDetailMapper.selectList(oneTaskEntity);
        }*/
        //2024-07-09 修改，项目周末任务完成情况单独提取出来 -- end
        WeekMonthReportEidt weekMonthReportEidt = adapterConverter.progressReportToWeekMonthReportEidt(progressReport);
        if (weekMonthReportEidt.getType() == MONTH_TYPE) {
            weekMonthReportEidt.setStatisticalTime(progressReport.getStatisticalStartTime().format(DateTimeFormatter.ofPattern("yyyy-MM")));
        }
        if (task.size() != 0) {
            List<OneAndKeyAndMilestoneTaskList> oneTaskList = adapterConverter.oneKeyMilestonesToOneAndKeyAndMilestoneTaskList(task);
            // 缺少图片回显 在根据详情表id获取每个图片的信息
            this.extendFile(oneTaskList);
            weekMonthReportEidt.setOneTaskList(oneTaskList);
        }
        if (keyTasks.size() != 0) {
            List<OneAndKeyAndMilestoneTaskList> keyTaskList = adapterConverter.oneKeyMilestonesToOneAndKeyAndMilestoneTaskList(keyTasks);
            this.extendFile(keyTaskList);
            weekMonthReportEidt.setKeyTaskList(keyTaskList);
        }
        if (milestones.size() != 0) {
            List<OneAndKeyAndMilestoneTaskList> milestoneList = adapterConverter.oneKeyMilestonesToOneAndKeyAndMilestoneTaskList(milestones);
            this.extendFile(milestoneList);
            weekMonthReportEidt.setMilestoneList(milestoneList);
        }
//        List<Long> ids = new ArrayList<Long>(Collections.singleton(progressWeekMonthReportCommand.getProjectId()));
        ProjectBasicResponse projectRMB = progressProjectRepository.getProject(progressWeekMonthReportCommand.getProjectId());
        if (null != projectRMB) {
            // 获取项目合同金额
            if (projectRMB.getContractCost() == null || projectRMB.getContractCost().intValue() == 0) {
                weekMonthReportEidt.setContractRMB(0L);
            } else {
                weekMonthReportEidt.setContractRMB(projectRMB.getContractCost().longValue());
            }
        }
        Integer maxAccumulationOutput = 0;
        // 如果是月报点击 编辑时需要根据统计结束时段 查询出小于这个时段的上报产值累加 作为页面累计值显示。
        if (progressReport != null && progressReport.getType() == MONTH_TYPE) {
            // 根据统计时段 结束值查找最大的 累计产值
            maxAccumulationOutput = progressReportMapper.findMaxAccumulationOutput(progressReport);
//            LocalDateTime.parse(progressReport.getStatisticalEndTime().toString(), DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"))
            weekMonthReportEidt.setAccumulationOutput(maxAccumulationOutput.longValue() + (progressReport.getReportOutputValue() != null ? progressReport.getReportOutputValue() : 0l));
        }else if (progressReport != null && progressReport.getType() == WEEK_TYPE){
            weekMonthReportEidt.setAccumulationOutput(progressReport.getAccumulationOutput() != null ? progressReport.getAccumulationOutput() : 0l);
        }
        return weekMonthReportEidt;
    }

    private void extendFile(List<OneAndKeyAndMilestoneTaskList> milestones) {
        Set<String> progressReportDetailIds = new HashSet<>();
        Set<String> attachmentKeys = new HashSet<>();
        for (OneAndKeyAndMilestoneTaskList progressReportDetailEntity : milestones) {
            progressReportDetailIds.add(progressReportDetailEntity.getId() + progressReportDetailEntity.getProgressWeekMonthReportId());
        }
        //通过附表实体类的周月报详情id，查找附表key
        LambdaQueryWrapper<ProgressAttachmentImageEntity> progressAttachmentQueryWrapper = new LambdaQueryWrapper<>();
        progressAttachmentQueryWrapper.in(ProgressAttachmentImageEntity::getProgressWeekMonthDetailId, progressReportDetailIds);
        List<ProgressAttachmentImageEntity> progressAttachmentImageEntities = progressAttachmentImageMapper.selectList(progressAttachmentQueryWrapper);
        Map<String, List<String>> progressAttachmentKeysMap = new HashMap<>();
        for (ProgressAttachmentImageEntity entity : progressAttachmentImageEntities) {
            List<String> attachmentKeysByEquipmentId = progressAttachmentKeysMap.getOrDefault(entity.getProgressWeekMonthDetailId(), new ArrayList<>());
            attachmentKeysByEquipmentId.add(entity.getSignKey());
            //HashMap中存储eqpId与attachmentKeys
            progressAttachmentKeysMap.put(entity.getProgressWeekMonthDetailId(), attachmentKeysByEquipmentId);
            attachmentKeys.add(entity.getSignKey());
        }
        List<File> files = new ArrayList<>();
        if (com.baomidou.mybatisplus.core.toolkit.CollectionUtils.isNotEmpty(attachmentKeys)) {
            files = fileRepository.getFileList(FileQuery.builder().signKeys(new ArrayList<>(attachmentKeys)).build());
        }
        Map<String, File> attachmentMap = new HashMap<>();
        for (File attachment : files) {
            attachmentMap.put(attachment.getSignKey(), attachment);
        }
        for (OneAndKeyAndMilestoneTaskList progressReportDetailEntity : milestones) {
            List<File> attachments = new ArrayList<>();
            List<String> progressAttachmentKeys = progressAttachmentKeysMap.getOrDefault(progressReportDetailEntity.getId().toString() + progressReportDetailEntity.getProgressWeekMonthReportId().toString(), new ArrayList<>());
            for (String key : progressAttachmentKeys) {
                attachments.add(attachmentMap.getOrDefault(key, new File(key)));
            }
            progressReportDetailEntity.setAttachments(attachments);
        }
    }

    @Override
    public Integer findTimeCount(WeekMonthReportEidt weekMonthReportEidtQuery) {
        return progressReportMapper.findTimeCount(weekMonthReportEidtQuery);
    }

    @Override
    public WeekMonthReportEidt getWeekMonthReportOne(WeekMonthReportEidt weekMonthReportEidtNew) {
        LambdaQueryWrapper<ProgressReportEntity> progressReportWrapper = new LambdaQueryWrapper<>();
        progressReportWrapper.eq(ObjectUtils.isNotNull(weekMonthReportEidtNew.getId()), ProgressReportEntity::getId, weekMonthReportEidtNew.getId());
        ProgressReportEntity progressReportEntity = progressReportMapper.selectOne(progressReportWrapper);
        WeekMonthReportEidt weekMonthReportEidt = adapterConverter.progressReportEntityToWeekMonthReportEidt(progressReportEntity);
        return weekMonthReportEidt;
    }

    @Override
    public WeekMonthReportEidt saveReportAndDetial(WeekMonthReportEidt weekMonthReportEidt) {
        ProgressReportEntity progressReportEntity = adapterConverter.weekMonthReportEidtToProgressReportEntity(weekMonthReportEidt);
        progressReportEntity.setRecordUser(authorityUtil.getLoginAccess().getLastName());
        progressReportEntity.setCreatedUserId(authorityUtil.getPersonId());
        progressReportEntity.setLatestUpdatedDate(LocalDateTime.now());
        progressReportEntity.setRecordTime(LocalDateTime.now());
        progressReportEntity.setLatestUpdatedUserId(authorityUtil.getPersonId());
        progressReportEntity.setId(weekMonthReportEidt.getId());
        if (ObjectUtils.isNull(weekMonthReportEidt.getId())) {
            progressReportMapper.insert(progressReportEntity);
        }
        List<ProgressReportDetailEntity> reportDetailEntitieList = new ArrayList<>();
        if (ObjectUtils.isNotNull(weekMonthReportEidt.getId())) {
            LambdaQueryWrapper<ProgressReportDetailEntity> progressReportDetailWrapper = new LambdaQueryWrapper<>();
            progressReportDetailWrapper.eq(ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportEntity.getId());
            /*progressReportDetailWrapper.eq(ProgressReportDetailEntity::getProjectId, progressReportEntity.getProjectId());
            progressReportDetailWrapper.and(wrapper -> wrapper
                    .like(ProgressReportDetailEntity::getType, ONE_TYPE).or()
                    .like(ProgressReportDetailEntity::getType, KEY_TYPE).or()
                    .like(ProgressReportDetailEntity::getType, MILESTONES_TYPE)
            );*/
            //List<OneAndKeyAndMilestoneTaskList> allTask = Stream.of(weekMonthReportEidt.getOneTaskList(), weekMonthReportEidt.getMilestoneList(), weekMonthReportEidt.getKeyTaskList()).flatMap(Collection::stream).distinct().collect(Collectors.toList());
            List<OneAndKeyAndMilestoneTaskList> allTask = Stream.of(weekMonthReportEidt.getOneTaskList()).flatMap(Collection::stream).distinct().collect(Collectors.toList());

            allTask.forEach(v -> {
                if(ObjectUtils.isNotNull(v.getProgressWeekMonthReportId())){
                    LambdaQueryWrapper<ProgressAttachmentImageEntity> progressAttachmentImageQueryWrapper = new LambdaQueryWrapper<>();
                    progressAttachmentImageQueryWrapper.eq(ProgressAttachmentImageEntity::getProgressWeekMonthDetailId, v.getId().toString() + v.getProgressWeekMonthReportId().toString());
                    progressAttachmentImageMapper.delete(progressAttachmentImageQueryWrapper);
                }
                ProgressReportDetailEntity progressReportDetailEntity = adapterConverter.oneAndKeyAndMilestoneTaskListToV(v);
                if (ObjectUtils.isNotNull(v.getScheduleStartTime())) {
                    progressReportDetailEntity.setScheduleStartTime(v.getScheduleStartTime().atStartOfDay());
                }
                if (ObjectUtils.isNotNull(v.getScheduleEndTime())) {
                    progressReportDetailEntity.setScheduleEndTime(v.getScheduleEndTime().atStartOfDay());
                }
                if (ObjectUtils.isNotNull(v.getRealEndTime())) {
                    progressReportDetailEntity.setRealEndTime(v.getRealEndTime().atStartOfDay());
                }
                if (ObjectUtils.isNotNull(v.getRealStartTime())) {
                    progressReportDetailEntity.setRealStartTime(v.getRealStartTime().atStartOfDay());
                }
                progressReportDetailEntity.setLatestUpdatedDate(LocalDateTime.now());
                progressReportDetailEntity.setLatestUpdatedUserId(authorityUtil.getPersonId());
                reportDetailEntitieList.add(progressReportDetailEntity);//保存的数据
                if (!v.getAttachments().isEmpty()) {
                    v.getAttachments().forEach(m -> {
                        progressAttachmentImageMapper.insert(ProgressAttachmentImageEntity.builder().progressWeekMonthDetailId(v.getId().toString() + v.getProgressWeekMonthReportId().toString()).signKey(m.getSignKey()).build());
                    });
                }
            });



            //比对数据库中的数据跟保存的数据，获取删除的数据

            /*LambdaQueryWrapper<ProgressReportDetailEntity> milestonesEntity = new LambdaQueryWrapper<>();
            milestonesEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportEntity.getId());
            milestonesEntity.eq(ProgressReportDetailEntity::getProjectId, progressReportEntity.getProjectId());
            milestonesEntity.like(ProgressReportDetailEntity::getType, MILESTONES_TYPE);
            milestonesEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
            List<ProgressReportDetailEntity> milestones = progressReportDetailMapper.selectList(milestonesEntity);
            LambdaQueryWrapper<ProgressReportDetailEntity> keyTaskEntity = new LambdaQueryWrapper<>();
            keyTaskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportEntity.getId());
            keyTaskEntity.eq(ProgressReportDetailEntity::getProjectId, progressReportEntity.getProjectId());
            keyTaskEntity.like(ProgressReportDetailEntity::getType, KEY_TYPE);
            keyTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
            List<ProgressReportDetailEntity> keyTasks = progressReportDetailMapper.selectList(keyTaskEntity);
            LambdaQueryWrapper<ProgressReportDetailEntity> oneTaskEntity = new LambdaQueryWrapper<>();
            oneTaskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportEntity.getId());
            oneTaskEntity.eq( ProgressReportDetailEntity::getProjectId, progressReportEntity.getProjectId());
            oneTaskEntity.like(ProgressReportDetailEntity::getType, ONE_TYPE);
            oneTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
            List<ProgressReportDetailEntity> oneTasks = progressReportDetailMapper.selectList(oneTaskEntity);
            LambdaQueryWrapper<ProgressReportDetailEntity> twoTaskEntity = new LambdaQueryWrapper<>();
            twoTaskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportEntity.getId());
            twoTaskEntity.eq( ProgressReportDetailEntity::getProjectId, progressReportEntity.getProjectId());
            twoTaskEntity.like(ProgressReportDetailEntity::getType, TWO_TYPE);
            oneTaskEntity.orderByAsc(ProgressReportDetailEntity::getSortIndex);
            List<ProgressReportDetailEntity> twoTasks = progressReportDetailMapper.selectList(twoTaskEntity);
            List<ProgressReportDetailEntity> detailList = Stream.of(oneTasks, milestones, keyTasks,twoTasks).flatMap(Collection::stream).distinct().collect(Collectors.toList());*/
            //获取数据库中的数据,并删除
            LambdaQueryWrapper<ProgressReportDetailEntity> taskEntity = new LambdaQueryWrapper<>();
            taskEntity.eq( ProgressReportDetailEntity::getProgressWeekMonthReportId, progressReportEntity.getId());
            taskEntity.eq(ProgressReportDetailEntity::getProjectId, progressReportEntity.getProjectId());
            taskEntity.orderByAsc(ProgressReportDetailEntity::getNamePrefix);
            progressReportDetailMapper.delete(taskEntity);


            //获取删除的数据

            /*List<ProgressReportDetailEntity> list1 = new ArrayList<>();//传过来的数据
            List<ProgressReportDetailEntity> list2 = new ArrayList<>();//数据库的数据*/
            reportDetailEntitieList.forEach(v->{
                if (ObjectUtils.isNull(v.getProgressWeekMonthReportId())) {
                    v.setProjectId(progressReportEntity.getProjectId());
                    v.setProgressWeekMonthReportId(progressReportEntity.getId());
                }
                /*ProgressReportDetailEntity model = new ProgressReportDetailEntity();
                model.setProjectId(v.getProjectId());
                model.setId(v.getId());
                model.setType(v.getType());
                model.setProgressWeekMonthReportId(v.getProgressWeekMonthReportId());
                list1.add(model);*/
            });

            /*detailList.forEach(v->{
                ProgressReportDetailEntity model = new ProgressReportDetailEntity();
                model.setProjectId(v.getProjectId());
                model.setId(v.getId());
                model.setType(v.getType());
                model.setProgressWeekMonthReportId(v.getProgressWeekMonthReportId());
                list2.add(model);
            });*/
            /*if(list2.size() > 0){
                List<ProgressReportDetailEntity> diff = list2.stream().filter(item -> !list1.contains(item)).collect(Collectors.toList());
                List<ProgressReportDetailEntity> diff1 = list1.stream().filter(item -> !list2.contains(item)).collect(Collectors.toList());
                diff.addAll(diff1);//需要删除的数据
                diff.forEach(a->{
                    LambdaQueryWrapper<ProgressReportDetailEntity> lambdaQueryWrapper = new LambdaQueryWrapper<>();
                    lambdaQueryWrapper.eq(ProgressReportDetailEntity ::getId,a.getId());
                    lambdaQueryWrapper.eq(ProgressReportDetailEntity ::getProgressWeekMonthReportId,progressReportEntity.getId());
                    lambdaQueryWrapper.eq(ProgressReportDetailEntity ::getType,a.getType());
                    lambdaQueryWrapper.eq(ProgressReportDetailEntity ::getProjectId,a.getProjectId());
                    progressReportDetailMapper.delete(lambdaQueryWrapper);
                });
            }*/

            //新增
            //去重

            if (!reportDetailEntitieList.isEmpty()) {
                reportDetailEntitieList.forEach(b -> {
                    b.setLatestUpdatedDate(LocalDateTime.now());
                    b.setLatestUpdatedUserId(authorityUtil.getPersonId());
                    progressReportDetailMapper.insert(b);
                });
            }
            progressReportMapper.updateById(progressReportEntity);
        }
        return adapterConverter.progressReportEntityToWeekMonthReportEidt(progressReportEntity);
    }

    @Override
    public String monthWeekReportCreateSum(WeekMonthReportType weekMonthReportType) {
        // 开工时间-当日时间项目总体完成XX%，进度正常/滞后XX天。
        String context = "";
        // 完成百分比（月报中累计上报产值/项目合同金额）
        ProjectBasicResponse project = progressProjectRepository.getProject(weekMonthReportType.getProjectId());
        // 获取项目合同金额
        Long accumulationOutput = 0L;
//        if(project.getjiener() != 0){
//            accumulationOutput = project.getjiener();
//        }
        // 开工时间 取项目任意任务中实际开始时间最早的时间
        String startWorkTime = progressReportDetailMapper.startWorkTime(weekMonthReportType);
        // 如果有滞后项目 就取所有滞后里，时间最长的 如果都是正常显示正常
        String type = progressReportDetailMapper.type(weekMonthReportType);
        if (StringUtils.isBlank(type)) {
            type = "正常";
        }
        // TODO: 2023/4/10 hxm 修改生成周报总结模板(二次提交)
        if(weekMonthReportType.getType().equals(2L)){
            context = startWorkTime + " - " + new String(DateTimeFormatter.ofPattern("yyyy年MM月dd").format(LocalDateTime.now())) + "项目总体完成" + accumulationOutput + "%,"
                    + "进度" + type + "天";
        }
        if(weekMonthReportType.getType().equals(1L)){
            context = "截止到" + new String(DateTimeFormatter.ofPattern("yyyy年MM月dd").format(LocalDateTime.now())) + "，"
                    + (StringUtils.isBlank(type) ? "进度正常" : "项目进度比计划" + type + "天");
        }

        return context;
    }

    @Override
    @Transactional
    public String monthReportCreate(MonthReportCreate monthReportCreate) {
        // 根据统计时间段分开时间
        LocalDateTime statisticalTime = LocalDateTime.parse(monthReportCreate.getStatisticalTime() + "-01 00:00:00", DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss"));
        LocalDateTime statisticalStartTime = statisticalTime.with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0);
        LocalDateTime statisticalEndTime = statisticalTime.with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59);
        WeekMonthReportEidt weekMonthReportEidt = adapterConverter.monthReportCreateToWeekMonthReportEidt(monthReportCreate);
        weekMonthReportEidt.setStatisticalStartTime(statisticalStartTime);
        weekMonthReportEidt.setStatisticalEndTime(statisticalEndTime);
        ProgressReportEntity progressReportEntity = adapterConverter.monthReportCreateToProgressReportEntity(monthReportCreate);
        progressReportEntity.setStatisticalStartTime(statisticalStartTime);
        progressReportEntity.setStatisticalEndTime(statisticalEndTime);
        // 判断月报统计时间段是否存在 存在不新增并把月报是否显示到列表状态0 显示，1不显示 为显示
        String firstDay = DateUtil.format(statisticalStartTime, "yyyy-MM-dd HH:mm:ss");
        String lastDay = DateUtil.format(statisticalEndTime, "yyyy-MM-dd HH:mm:ss");
        LambdaQueryWrapper<ProgressReportEntity> reportEntity = new LambdaQueryWrapper<>();
        reportEntity.eq(ObjectUtils.isNotNull(firstDay), ProgressReportEntity::getStatisticalStartTime, firstDay);
        reportEntity.eq(ObjectUtils.isNotNull(lastDay), ProgressReportEntity::getStatisticalEndTime, lastDay);
        reportEntity.eq(ObjectUtils.isNotNull(monthReportCreate.getProjectId()), ProgressReportEntity::getProjectId, monthReportCreate.getProjectId());
        ProgressReportEntity countSUM = progressReportMapper.selectOne(reportEntity);

        if (countSUM != null) {
            // 更新这条数据 月报是否显示到列表状态0 显示，1不显示
            countSUM.setDisplayStatus(0L);
            progressReportMapper.updateById(countSUM);
            throw LogicException.raise(new ErrorItem(26, "该月项目月报已经存在，无需在新增！！"));
        }

        // 可以新建月报 根据项目的id 查找对应的任务存入 月报表中
        LambdaQueryWrapper<ProgressEntity> progressEntity = new LambdaQueryWrapper<>();
        progressEntity.eq(ObjectUtils.isNotNull(weekMonthReportEidt.getProjectId()), ProgressEntity::getProjectId, weekMonthReportEidt.getProjectId());
        ProgressEntity progress = progressMapper.selectOne(progressEntity);

        // 新增的月报统计时间段小于已发布并审批通过的 数据 就无法新增
        Integer count = progressReportMapper.findTimeCount(weekMonthReportEidt);
        Integer maxAccumulationOutput = progressReportMapper.findMaxAccumulationOutput(progressReportEntity);
        List<ProgressAttachmentImageEntity> progressAttachmentImageEntitys = new ArrayList<>();
        List<ProgressReportDetailEntity> progressReportDetailEntitys = new ArrayList<>();
        if (progress != null) {
            // 查询该项目是否完成
            ProgressEntity projectCom = progressMapper.getProjectCom(weekMonthReportEidt.getProjectId());
            if (projectCom == null) {
                throw LogicException.raise(new ErrorItem(26, "该项目已完成，无需再次新增！！"));
            }
            if (count == 0 && countSUM == null) {
                LambdaQueryWrapper<ProgressDetailEntity> progressDetailEntity = new LambdaQueryWrapper<>();
                progressDetailEntity.eq(ObjectUtils.isNotNull(weekMonthReportEidt.getProjectId()), ProgressDetailEntity::getProjectId, weekMonthReportEidt.getProjectId());
                progressDetailEntity.eq(ObjectUtils.isNotNull(progress.getId()), ProgressDetailEntity::getProjectScheduleId, progress.getId());
                List<ProgressDetailEntity> progressDetailList = projectScheduleDetaillMapper.selectList(progressDetailEntity);
                if (progressDetailList.size() != 0) {
                    ProgressReportEntity progressReport = new ProgressReportEntity();
                    progressReport.setName(progress.getName());
                    progressReport.setRecordUser(authorityUtil.getLoginAccess().getLastName());
                    progressReport.setProjectId(progress.getProjectId());
                    progressReport.setStatisticalStartTime(statisticalStartTime);
                    progressReport.setStatisticalEndTime(statisticalEndTime);
                    progressReport.setRecordTime(LocalDateTime.now());
                    progressReport.setType(2L);
                    progressReport.setDisplayStatus(0L);
                    progressReport.setAccumulationOutput(maxAccumulationOutput.longValue());
                    progressReport.setCreatedDate(LocalDateTime.now());
                    progressReport.setCreatedUserId(authorityUtil.getPersonId());
                    progressReportMapper.insert(progressReport);
                    // 插入详情表
                    // 2024-07-26 默认取上个月填报的任务数据

                    String startTime = "";
                    String endTime = "";
                    if(progressReport.getType() == 2){
                        //月报
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                        LocalDateTime localDateStartTime = progressReport.getStatisticalStartTime();
                        LocalDateTime localDateEndTime = progressReport.getStatisticalEndTime();
                        LocalDateTime localDateStartTimeBefor =  localDateStartTime.minus(1, ChronoUnit.MONTHS);
                        LocalDateTime localDateEndTimeBefor =    localDateStartTimeBefor.with(TemporalAdjusters.lastDayOfMonth());
                        startTime = localDateStartTimeBefor.format(formatter) + " 00:00:00";
                        endTime = localDateEndTimeBefor.format(formatter) +" 23:59:59";
                    }
                    if(progressReport.getType() == 1){
                        //周报
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                        LocalDateTime localDateStartTime = progressReport.getStatisticalStartTime();
                        LocalDateTime localDateEndTime = progressReport.getStatisticalEndTime();
                        LocalDateTime localDateStartTimeBefor =  localDateStartTime.minus(7, ChronoUnit.DAYS);
                        LocalDateTime localDateEndTimeBefor =  localDateEndTime.minus(7, ChronoUnit.DAYS);
                        startTime = localDateStartTimeBefor.format(formatter);
                        endTime = localDateEndTimeBefor.format(formatter);
                    }
                    List<ProgressReportDetailEntity> oneTasks = this.getDataByLastTime(progress.getProjectId(),progressReport.getType(),startTime,endTime,progress.getId());
                    //查询主表数据
                    oneTasks.forEach(progressReportDetail ->{
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setCreatedUserId(authorityUtil.getPersonId());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);

                        List<ProgressAttachmentImageEntity> progressAttachmentImageEntityList = progressReportDetail.getProgressAttachmentImageEntityList();
                        progressAttachmentImageEntityList.forEach(attachment->{
                            attachment.setProgressWeekMonthDetailId(progressReportDetail.getId().toString()+progressReport.getId().toString());
                            progressAttachmentImageEntitys.add(attachment);
                        });
                    });

                    /*String startTime = "";
                    String endTime = "";
                    DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                    if(progressReport.getType() == 2){
                        //月报
                        LocalDateTime localDateStartTime = progressReport.getStatisticalStartTime();
                        LocalDateTime localDateEndTime = progressReport.getStatisticalEndTime();
                        LocalDateTime localDateStartTimeBefor =  localDateStartTime.minus(1, ChronoUnit.MONTHS);
                        LocalDateTime localDateEndTimeBefor =  localDateEndTime.minus(1, ChronoUnit.MONTHS);
                        startTime = localDateStartTimeBefor.format(formatter);
                        endTime = localDateEndTimeBefor.format(formatter);
                    }
                    if(progressReport.getType() == 1){
                        //周报
                        LocalDateTime localDateStartTime = progressReport.getStatisticalStartTime();
                        LocalDateTime localDateEndTime = progressReport.getStatisticalEndTime();
                        LocalDateTime localDateStartTimeBefor =  localDateStartTime.minus(7, ChronoUnit.DAYS);
                        LocalDateTime localDateEndTimeBefor =  localDateEndTime.minus(7, ChronoUnit.DAYS);
                        startTime = localDateStartTimeBefor.format(formatter);
                        endTime = localDateEndTimeBefor.format(formatter);
                    }
                    List<ProgressReportDetailEntity> oneTasks = this.getDataByLastTime(progress.getProjectId(),progressReport.getType(),startTime,endTime);
                    oneTasks.forEach(progressReportDetail ->{
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setCreatedUserId(authorityUtil.getPersonId());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);
                    });*/

                    /*for (ProgressDetailEntity pogressDetail : progressDetailList) {
                        ProgressReportDetailEntity progressReportDetail = adapterConverter.pogressDetailToProgressReportDetailEntity(pogressDetail);
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setCreatedUserId(authorityUtil.getPersonId());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);
//                        progressReportDetailMapper.insert(progressReportDetail);
                        LambdaQueryWrapper<ProjectAttachmentImageEntity> projectAttachmentImage = new LambdaQueryWrapper<>();
                        projectAttachmentImage.eq(ObjectUtils.isNotNull(pogressDetail.getId()), ProjectAttachmentImageEntity::getProjectScheduleDetailId, pogressDetail.getId());
                        List<ProjectAttachmentImageEntity> images = projectAttachmentImageMapper.selectList(projectAttachmentImage);
                        // 根据详情id查询图片
                        images.forEach(v -> {
                            ProgressAttachmentImageEntity progressAttachmentImageEntity = adapterConverter.vToProgressAttachmentImageEntity(v);
                            progressAttachmentImageEntity.setProgressWeekMonthDetailId(progressReportDetail.getId().toString() + progressReport.getId().toString());
                            progressAttachmentImageEntitys.add(progressAttachmentImageEntity);
                        });
                    }*/
                    if (!progressReportDetailEntitys.isEmpty()) {
                        progressReportDetailMapper.insertBatch(progressReportDetailEntitys);
                    }
                    if (!progressAttachmentImageEntitys.isEmpty()) {
                        progressAttachmentImageMapper.insertBatch(progressAttachmentImageEntitys);
                    }
                }
            } else {
                throw LogicException.raise(new ErrorItem(26, "统计时段的开始时间，必须晚于已发布报告的截止时间"));
            }
        } else {
            throw LogicException.raise(new ErrorItem(26, "该项目没有进度计划，不能新增"));
        }
        return null;
    }

    @Override
    @Transactional
    public Boolean weekReportCreate(String date) {
        log.info("开始生成进度周报，参数："+date);
        // 查询是否项目表中所有的项目然后生成周报
        List<ProgressEntity> progressList = progressMapper.findAllProject();
        log.info("生成进度周报，查询所有项目个数："+progressList.size());
        WeekFields weekFields = WeekFields.ISO;
        LocalDateTime startEndDate = null;
        if (ObjectUtils.isNotNull(date)) {
            startEndDate = LocalDate.parse(date, ISO_DATE).atStartOfDay();
        } else {
            startEndDate = LocalDateTime.now();
        }
        LocalDateTime localDate1 = startEndDate.with(weekFields.dayOfWeek(), 1L);
        LocalDateTime lastDaylocalDate1 = startEndDate.with(weekFields.dayOfWeek(), 7L);
        String firstDay = DateUtil.format(localDate1.withHour(0).withMinute(0).withSecond(0), "yyyy-MM-dd HH:mm:ss");
        String lastDay = DateUtil.format(lastDaylocalDate1.withHour(23).withMinute(59).withSecond(59), "yyyy-MM-dd HH:mm:ss");
        log.info("生成进度周报，查询开始时间：【"+firstDay+"】,结束时间:【"+lastDay+"】");
        // 获取今天的时间、一周之后的时间
        // 查询时间段内是否存在数据 存在不新建
        progressList.forEach(v -> {
            LambdaQueryWrapper<ProgressReportEntity> progressReportEntity = new LambdaQueryWrapper<>();
            progressReportEntity.eq(ObjectUtils.isNotNull(firstDay), ProgressReportEntity::getStatisticalStartTime, firstDay);
            progressReportEntity.eq(ObjectUtils.isNotNull(lastDay), ProgressReportEntity::getStatisticalEndTime, lastDay);
            progressReportEntity.eq(ObjectUtils.isNotNull(v.getProjectId()), ProgressReportEntity::getProjectId, v.getProjectId());
            List<ProgressReportEntity> progressReportList = progressReportMapper.selectList(progressReportEntity);
            if (progressReportList.size() == 0) {
                // 生成周报 插入 progress_week_month_report
                // 插入 progress_week_month_detail
                log.info("开始生成进度周报，项目ID：{}",v.getProjectId());
                LambdaQueryWrapper<ProgressDetailEntity> progressDetailEntity = new LambdaQueryWrapper<>();
                progressDetailEntity.eq(ObjectUtils.isNotNull(v.getProjectId()), ProgressDetailEntity::getProjectId, v.getProjectId());
                progressDetailEntity.eq(ObjectUtils.isNotNull(v.getId()), ProgressDetailEntity::getProjectScheduleId, v.getId());
                List<ProgressDetailEntity> progressDetailList = projectScheduleDetaillMapper.selectList(progressDetailEntity);
                if (progressDetailList.size() != 0) {
                    log.info("开始生成进度周报，projectId：{}，projectScheduleId：{}",v.getProjectId(),v.getId());
                    ProgressReportEntity progressReport = new ProgressReportEntity();
                    progressReport.setName(v.getName());
                    progressReport.setProjectId(v.getProjectId());
                    progressReport.setStatisticalStartTime(LocalDateTime.parse(firstDay, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                    progressReport.setStatisticalEndTime(LocalDateTime.parse(lastDay, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                    progressReport.setRecordTime(LocalDateTime.now());
                    progressReport.setType(1L);
                    progressReport.setDisplayStatus(0L);
                    progressReport.setAccumulationOutput(v.getAccumulationOutput() != null ? v.getAccumulationOutput().longValue() : 0l);
//                    progressReport.setAccumulationOutputnOutput(maxAccumulationOutput.longValue());
                    progressReport.setCreatedDate(LocalDateTime.now());
                    progressReportMapper.insert(progressReport);
                    log.info("生成周报，插入数据到主表成功，ID为:{}",progressReport.getId());
                    List<ProgressAttachmentImageEntity> progressAttachmentImageEntitys = new ArrayList<>();
                    List<ProgressReportDetailEntity> progressReportDetailEntitys = new ArrayList<>();
                    // 插入详情表
                    //2024-07-26 默认获取上一周填报的任务
                    /*String beforFirstDay = DateUtil.format(localDate1.minusWeeks(1).withHour(0).withMinute(0).withSecond(0), "yyyy-MM-dd HH:mm:ss");
                    String beforLastDay = DateUtil.format(lastDaylocalDate1.minusWeeks(1).withHour(23).withMinute(59).withSecond(59), "yyyy-MM-dd HH:mm:ss");
                    LambdaQueryWrapper<ProgressReportEntity> beforProgressReportEntityQuery = new LambdaQueryWrapper<>();
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getProjectId,progressReport.getProjectId());
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getStatisticalStartTime,beforFirstDay);
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getStatisticalEndTime,beforLastDay);
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getType,1l);
                    ProgressReportEntity beforProgressReportEntity = progressReportMapper.selectOne(beforProgressReportEntityQuery);
                    LambdaQueryWrapper<ProgressReportDetailEntity> detailEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
                    detailEntityLambdaQueryWrapper.eq(ProgressReportDetailEntity ::getProgressWeekMonthReportId,beforProgressReportEntity.getId());
                    List<ProgressReportDetailEntity> entityList = progressReportDetailMapper.selectList(detailEntityLambdaQueryWrapper);
                    entityList.forEach(progressReportDetail ->{
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setCreatedUserId(authorityUtil.getPersonId());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);
                    });*/
                    String startTime = "";
                    String endTime = "";
                    if(progressReport.getType() == 2){
                        //月报
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd");
                        LocalDateTime localDateStartTime = progressReport.getStatisticalStartTime();
                        LocalDateTime localDateEndTime = progressReport.getStatisticalEndTime();
                        LocalDateTime localDateStartTimeBefor =  localDateStartTime.minus(1, ChronoUnit.MONTHS);
                        LocalDateTime localDateEndTimeBefor =    localDateStartTimeBefor.with(TemporalAdjusters.lastDayOfMonth());
                        startTime = localDateStartTimeBefor.format(formatter) + " 00:00:00";
                        endTime = localDateEndTimeBefor.format(formatter) +" 23:59:59";
                    }
                    if(progressReport.getType() == 1){
                        //周报
                        DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
                        LocalDateTime localDateStartTime = progressReport.getStatisticalStartTime();
                        LocalDateTime localDateEndTime = progressReport.getStatisticalEndTime();
                        LocalDateTime localDateStartTimeBefor =  localDateStartTime.minus(7, ChronoUnit.DAYS);
                        LocalDateTime localDateEndTimeBefor =  localDateEndTime.minus(7, ChronoUnit.DAYS);
                        startTime = localDateStartTimeBefor.format(formatter);
                        endTime = localDateEndTimeBefor.format(formatter);
                    }
                    List<ProgressReportDetailEntity> oneTasks = this.getDataByLastTime(progressReport.getProjectId(),progressReport.getType(),startTime,endTime,v.getId());
                    oneTasks.forEach(progressReportDetail ->{
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setCreatedUserId(authorityUtil.getPersonId());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);

                        List<ProgressAttachmentImageEntity> progressAttachmentImageEntityList = progressReportDetail.getProgressAttachmentImageEntityList();
                        progressAttachmentImageEntityList.forEach(attachment->{
                            attachment.setProgressWeekMonthDetailId(progressReportDetail.getId().toString()+progressReport.getId().toString());
                            progressAttachmentImageEntitys.add(attachment);
                        });
                    });

                    /*for (ProgressDetailEntity pogressDetail : progressDetailList) {
                        ProgressReportDetailEntity progressReportDetail = adapterConverter.pogressDetailToProgressReportDetailEntity(pogressDetail);
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);
//                        progressReportDetailMapper.insert(progressReportDetail);
                        LambdaQueryWrapper<ProjectAttachmentImageEntity> projectAttachmentImage = new LambdaQueryWrapper<>();
                        projectAttachmentImage.eq(ObjectUtils.isNotNull(pogressDetail.getId()), ProjectAttachmentImageEntity::getProjectScheduleDetailId, pogressDetail.getId());
                        List<ProjectAttachmentImageEntity> images = projectAttachmentImageMapper.selectList(projectAttachmentImage);
                        // 根据详情id查询图片
                        images.forEach(b -> {
                            ProgressAttachmentImageEntity progressAttachmentImageEntity = adapterConverter.vToProgressAttachmentImageEntity(b);
                            progressAttachmentImageEntity.setProgressWeekMonthDetailId(progressReportDetail.getId().toString() + progressReport.getId().toString());
                            progressAttachmentImageEntitys.add(progressAttachmentImageEntity);
                        });
                    }*/
                    if (!progressReportDetailEntitys.isEmpty()) {
                        progressReportDetailMapper.insertBatch(progressReportDetailEntitys);
                        log.info("生成周报/月报，插入数据到副表【progress_week_month_detail】，成功");
                    }
                    if (!progressAttachmentImageEntitys.isEmpty()) {
                        progressAttachmentImageMapper.insertBatch(progressAttachmentImageEntitys);
                    }
                    log.info("生成进度周报完成，projectId：{}，projectScheduleId：{}",v.getProjectId(),v.getId());
                }
            }
        });
        return true;
    }

    @Override
    public Integer findWeekReport(String firstDay, int weekType, Long id, Long projectId, int type) {
        LambdaQueryWrapper<ProgressReportEntity> progressReportEntity = new LambdaQueryWrapper<>();
        progressReportEntity.eq(ObjectUtils.isNotNull(firstDay), ProgressReportEntity::getStatisticalStartTime, firstDay);
        progressReportEntity.eq(ObjectUtils.isNotNull(weekType), ProgressReportEntity::getType, weekType);
        progressReportEntity.eq(ObjectUtils.isNotNull(projectId), ProgressReportEntity::getProjectId, projectId);
//        progressReportEntity.eq(ObjectUtils.isNotNull(id), ProgressReportEntity::getId, id);
        progressReportEntity.eq(ObjectUtils.isNotNull(type), ProgressReportEntity::getStatus, type);
        progressReportEntity.isNull(ProgressReportEntity::getConstructionManagerApproval);
        return progressReportMapper.selectCount(progressReportEntity);
    }

    @Override
    public List<ProgressReportEntity> getAllProgressReport() {
//        LambdaQueryWrapper<ProgressReportEntity> progressReportEntity = new LambdaQueryWrapper<>();
//        progressReportEntity.groupBy(ProgressReportEntity::getProjectId);
        return progressReportMapper.findAllProgressReport();
    }

    @Override
    public Integer findMonthReport(int monthType, Long projectId, Long id, int weekMonthDraftStatus) {
        return progressReportMapper.countMonth(monthType, projectId, id, weekMonthDraftStatus);
    }

    @Override
    @Transactional
    public Boolean monthReportCreateTask() {
        List<ProgressEntity> progressList = progressMapper.findAllProject();
        progressList.forEach(v -> {
            String firstDay = DateUtil.format(LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0), "yyyy-MM-dd HH:mm:ss");
            String lastDay = DateUtil.format(LocalDateTime.now().with(TemporalAdjusters.lastDayOfMonth()).withHour(23).withMinute(59).withSecond(59), "yyyy-MM-dd HH:mm:ss");
            ProgressReportEntity progressReportEntity = new ProgressReportEntity();
            progressReportEntity.setProjectId(v.getProjectId());
            progressReportEntity.setStatisticalStartTime(LocalDateTime.now().with(TemporalAdjusters.firstDayOfMonth()).withHour(0).withMinute(0).withSecond(0));
            Integer maxAccumulationOutput = progressReportMapper.findMaxAccumulationOutput(progressReportEntity);
            LambdaQueryWrapper<ProgressReportEntity> reportEntity = new LambdaQueryWrapper<>();
            reportEntity.eq(ObjectUtils.isNotNull(firstDay), ProgressReportEntity::getStatisticalStartTime, firstDay);
            reportEntity.eq(ObjectUtils.isNotNull(lastDay), ProgressReportEntity::getStatisticalEndTime, lastDay);
            reportEntity.eq(ObjectUtils.isNotNull(v.getProjectId()), ProgressReportEntity::getProjectId, v.getProjectId());
            ProgressReportEntity countSUM = progressReportMapper.selectOne(reportEntity);
            if (countSUM == null) {
                // 创建月报
                LambdaQueryWrapper<ProgressDetailEntity> progressDetailEntity = new LambdaQueryWrapper<>();
                progressDetailEntity.eq(ObjectUtils.isNotNull(v.getProjectId()), ProgressDetailEntity::getProjectId, v.getProjectId());
                progressDetailEntity.eq(ObjectUtils.isNotNull(v.getId()), ProgressDetailEntity::getProjectScheduleId, v.getId());
                List<ProgressDetailEntity> progressDetailList = projectScheduleDetaillMapper.selectList(progressDetailEntity);
                if (progressDetailList.size() != 0) {
                    ProgressReportEntity progressReport = new ProgressReportEntity();
                    progressReport.setName(v.getName());
                    progressReport.setProjectId(v.getProjectId());
                    progressReport.setStatisticalStartTime(LocalDateTime.parse(firstDay, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                    progressReport.setStatisticalEndTime(LocalDateTime.parse(lastDay, DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
                    progressReport.setRecordTime(LocalDateTime.now());
                    progressReport.setType(2L);
                    progressReport.setDisplayStatus(1L);
                    progressReport.setAccumulationOutput(maxAccumulationOutput.longValue());
                    progressReport.setCreatedDate(LocalDateTime.now());
                    progressReportMapper.insert(progressReport);
                    List<ProgressAttachmentImageEntity> progressAttachmentImageEntitys = new ArrayList<>();
                    List<ProgressReportDetailEntity> progressReportDetailEntitys = new ArrayList<>();
                    // 插入详情表
                    // 2024-07-26 默认取上个月的任务
                    String beforFirstDay = DateUtil.format(LocalDateTime.now().minusMonths(1), "yyyy-MM-dd HH:mm:ss");
                    String beforLastDay = DateUtil.format(LocalDateTime.now().minusMonths(1), "yyyy-MM-dd HH:mm:ss");
                    LambdaQueryWrapper<ProgressReportEntity> beforProgressReportEntityQuery = new LambdaQueryWrapper<>();
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getProjectId,v.getProjectId());
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getStatisticalStartTime,beforFirstDay);
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getStatisticalEndTime,beforLastDay);
                    beforProgressReportEntityQuery.eq(ProgressReportEntity ::getType,2l);
                    ProgressReportEntity beforProgressReportEntity = progressReportMapper.selectOne(beforProgressReportEntityQuery);
                    LambdaQueryWrapper<ProgressReportDetailEntity> detailEntityLambdaQueryWrapper = new LambdaQueryWrapper<>();
                    detailEntityLambdaQueryWrapper.eq(ProgressReportDetailEntity ::getProgressWeekMonthReportId,beforProgressReportEntity.getId());
                    List<ProgressReportDetailEntity> entityList = progressReportDetailMapper.selectList(detailEntityLambdaQueryWrapper);
                    entityList.forEach(progressReportDetail ->{
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setCreatedUserId(authorityUtil.getPersonId());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);
                    });
                    /*for (ProgressDetailEntity pogressDetail : progressDetailList) {
                        ProgressReportDetailEntity progressReportDetail = adapterConverter.pogressDetailToProgressReportDetailEntity(pogressDetail);
                        progressReportDetail.setCreatedDate(LocalDateTime.now());
                        progressReportDetail.setProgressWeekMonthReportId(progressReport.getId());
                        progressReportDetailEntitys.add(progressReportDetail);
//                        progressReportDetailMapper.insert(progressReportDetail);
                        LambdaQueryWrapper<ProjectAttachmentImageEntity> projectAttachmentImage = new LambdaQueryWrapper<>();
                        projectAttachmentImage.eq(ObjectUtils.isNotNull(pogressDetail.getId()), ProjectAttachmentImageEntity::getProjectScheduleDetailId, pogressDetail.getId());
                        List<ProjectAttachmentImageEntity> images = projectAttachmentImageMapper.selectList(projectAttachmentImage);
                        // 根据详情id查询图片
                        images.forEach(b -> {
                            ProgressAttachmentImageEntity progressAttachmentImageEntity = adapterConverter.vToProgressAttachmentImageEntity(b);
                            progressAttachmentImageEntity.setProgressWeekMonthDetailId(progressReportDetail.getId().toString() + progressReport.getId().toString());
                            progressAttachmentImageEntitys.add(progressAttachmentImageEntity);
                        });
                    }*/
                    if (!progressReportDetailEntitys.isEmpty()) {
                        progressReportDetailMapper.insertBatch(progressReportDetailEntitys);
                    }
                    if (!progressAttachmentImageEntitys.isEmpty()) {
                        progressAttachmentImageMapper.insertBatch(progressAttachmentImageEntitys);
                    }
                }
            }
        });
        return true;
    }

    @Override
    public List<Map<String, Object>> milestoneAndKeyLagging7(ProgressReport weekReport) {
        return progressReportDetailMapper.milestoneAndKeyLagging7(weekReport);
    }

}
